List of usage examples for java.util.concurrent ConcurrentHashMap get
public V get(Object key)
From source file:com.app.server.WarDeployer.java
public void removeServletFromSessionObject(WebAppConfig webAppConfig, String warDirectory) { Enumeration sessionKeys = sessionObjects.keys(); while (sessionKeys.hasMoreElements()) { String sessionKey = (String) sessionKeys.nextElement(); HttpSessionServer session = (HttpSessionServer) sessionObjects.get(sessionKey); ConcurrentHashMap servletMap = webAppConfig.getServlets(); Enumeration servlets = servletMap.keys(); while (servlets.hasMoreElements()) { String servletname = (String) servlets.nextElement(); Servlets servletsMapping = (Servlets) servletMap.get(servletname); /*log.info("SERVLETNAME:" + warDirectory// w ww . j ava2 s.c o m + servletsMapping.getServletName() + session.getAttribute("SERVLETNAME:" + warDirectory + servletsMapping.getServletName()));*/ session.removeAttribute("SERVLETNAME:" + warDirectory + servletsMapping.getServletName()); } } }
From source file:cc.osint.graphd.server.GraphServerHandler.java
public String executeRequest(Channel responseChannel, String clientId, ConcurrentHashMap<String, String> clientState, String request) throws Exception { StringBuffer rsb = new StringBuffer(); String cmd;/*from w w w .j a v a 2 s . c o m*/ String[] args; if (request.indexOf(GraphServerProtocol.SPACE) != -1) { cmd = request.substring(0, request.indexOf(GraphServerProtocol.SPACE)).trim().toLowerCase(); args = request.substring(request.indexOf(GraphServerProtocol.SPACE)).trim() .split(GraphServerProtocol.SPACE); } else { cmd = request.trim().toLowerCase(); args = new String[0]; } // USE GRAPH: use <graphName> if (cmd.equals(GraphServerProtocol.CMD_USE)) { if (null == nameGraphMap.get(args[0])) { rsb.append(GraphServerProtocol.R_ERR); rsb.append(" DB_NOT_EXIST"); } else { if (null != clientState.get(ST_DB)) clientState.remove(ST_DB); clientState.put(ST_DB, args[0]); rsb.append(GraphServerProtocol.R_OK); } // CREATE GRAPH: create <graphName> } else if (cmd.equals(GraphServerProtocol.CMD_CREATE)) { if (null != nameGraphMap.get(args[0])) { rsb.append(GraphServerProtocol.R_ERR); rsb.append(" DB_ALREADY_EXISTS"); } else { Graph newGraph = new Graph(args[0]); nameGraphMap.put(args[0], newGraph); WeakReference<Graph> graphRef = new WeakReference<Graph>(newGraph); GraphCommandExecutor graphCommandExecutor = new GraphCommandExecutor(args[0], graphRef); graphCommandExecutorService.execute(graphCommandExecutor); graphCommandExecutorMap.put(args[0], graphCommandExecutor); rsb.append(GraphServerProtocol.R_OK); } // DROP GRAPH: drop <graphName> } else if (cmd.equals(GraphServerProtocol.CMD_DROP)) { if (null == nameGraphMap.get(args[0])) { rsb.append(GraphServerProtocol.R_ERR); rsb.append(" DB_NOT_EXIST"); } else { nameGraphMap.remove(args[0]); graphCommandExecutorMap.remove(args[0]); // TODO: DROP <KEY> // TODO: KILL graphCommandExecutor (via poisonPill message) rsb.append(GraphServerProtocol.R_OK); } // NAME THIS CONNECTION: namecon <name> } else if (cmd.equals(GraphServerProtocol.CMD_NAMECON)) { clientState.put(ST_NAMECON, args[0] + "-" + clientId); rsb.append(clientState.get(ST_NAMECON)); rsb.append(GraphServerProtocol.NL); rsb.append(GraphServerProtocol.R_OK); // DUMP CLIENT STATE: clstate } else if (cmd.equals(GraphServerProtocol.CMD_CLSTATE)) { JSONObject result = new JSONObject(clientState); rsb.append(result.toString()); rsb.append(GraphServerProtocol.NL); rsb.append(GraphServerProtocol.R_OK); // SERVER STATUS: sstat } else if (cmd.equals(GraphServerProtocol.CMD_SSTAT)) { JSONObject result = new JSONObject(); JSONObject names = new JSONObject(); names.put("TYPE_FIELD", Graph.TYPE_FIELD); names.put("KEY_FIELD", Graph.KEY_FIELD); names.put("WEIGHT_FIELD", Graph.WEIGHT_FIELD); names.put("EDGE_SOURCE_FIELD", Graph.EDGE_SOURCE_FIELD); names.put("EDGE_TARGET_FIELD", Graph.EDGE_TARGET_FIELD); names.put("RELATION_FIELD", Graph.RELATION_FIELD); names.put("VERTEX_TYPE", Graph.VERTEX_TYPE); names.put("EDGE_TYPE", Graph.EDGE_TYPE); result.put("names", names); rsb.append(result.toString()); rsb.append(GraphServerProtocol.NL); rsb.append(GraphServerProtocol.R_OK); // LIST NAMED GRAPHS } else if (cmd.equals(GraphServerProtocol.CMD_LISTG)) { for (String name : nameGraphMap.keySet()) { rsb.append(name); rsb.append(GraphServerProtocol.NL); } rsb.append(GraphServerProtocol.R_OK); // GRAPH STATUS: gstat <name> } else if (cmd.equals(GraphServerProtocol.CMD_GSTAT)) { Graph gr0 = nameGraphMap.get(args[0]); if (null == gr0) { rsb.append(GraphServerProtocol.R_NOT_EXIST); } else { JSONObject result = new JSONObject(); result.put("vertex_count", gr0.numVertices()); result.put("edge_count", gr0.numEdges()); rsb.append(result.toString()); rsb.append(GraphServerProtocol.NL); rsb.append(GraphServerProtocol.R_OK); } } else { // // graph-specific operations // WeakReference<InboundChannelProcess> inboundChannelProcessRef = inboundChannelMap.get(clientId); // // async override handler // if (cmd.startsWith("&")) { cmd = cmd.substring(1); request = request.substring(1); responseChannel.write(graphCommandExecutorMap.get(clientState.get(GraphServerHandler.ST_DB)) .execute(responseChannel, clientId, clientState, inboundChannelProcessRef.get(), request, cmd, args) + GraphServerProtocol.NL); } else { // // graph-specific, queue-driven ordered operations // GraphCommand graphCommand = new GraphCommand(); graphCommand.responseChannel = responseChannel; graphCommand.clientId = clientId; graphCommand.clientState = clientState; graphCommand.inboundChannelProcess = inboundChannelProcessRef.get(); graphCommand.request = request; graphCommand.cmd = cmd; graphCommand.args = args; graphCommand.poisonPill = false; graphCommandExecutorMap.get(clientState.get(GraphServerHandler.ST_DB)).queue(graphCommand); } // a null return value indicates it's been queued for execution // by the appropriate GraphCommandExecutor return null; } // unknown request if (rsb.toString().equals("")) { log.info("GraphServerProtocol.R_UNK: " + cmd); rsb.append(GraphServerProtocol.R_UNK); rsb.append(GraphServerProtocol.SPACE); rsb.append(cmd); } rsb.append(GraphServerProtocol.NL); return rsb.toString(); }
From source file:org.seedstack.mqtt.internal.MqttPluginTest.java
/** * Test method for/*from w w w.j a v a 2 s. c o m*/ * {@link org.seedstack.mqtt.internal.MqttPlugin#init(io.nuun.kernel.api.plugin.context.InitContext)} * . */ @Test public void testInitWithDefaultReconnection(@Mocked final Configuration configuration) { final String clientName = "clientOK1"; final String[] clients = { clientName }; final Collection<Class<?>> classes = new ArrayList<Class<?>>(); MqttPlugin plugin = new MqttPlugin(); final String defaultConfigString = "xx"; new Expectations() { { application.getConfiguration(); result = configuration; configuration.subset(MQTT_PLUGIN_CONFIGURATION_PREFIX); result = configuration; configuration.getStringArray(CONNECTION_CLIENTS); result = clients; configuration.getString(BROKER_URI); result = defaultConfigString; specs.get(any); result = classes; } }; new MockUp<MqttClient>() { @Mock public void $init(String serverURI, String clientId) throws MqttException { } }; plugin.init(initContext); MqttClientDefinition def = new MqttClientDefinition(defaultConfigString, defaultConfigString); ConcurrentHashMap<String, MqttClientDefinition> defs = Deencapsulation.getField(plugin, "mqttClientDefinitions"); Assertions.assertThat(defs).isNotEmpty(); MqttClientDefinition clientDef = defs.get(clientName); Assertions.assertThat(clientDef.getReconnectionInterval()).isEqualTo(def.getReconnectionInterval()); Assertions.assertThat(clientDef.getReconnectionMode()).isEqualTo(def.getReconnectionMode()); }
From source file:com.web.server.EARDeployer.java
/** * This method removes the executor services from the executor services * map.//w ww . ja v a 2 s . com * * @param jarFile * @param classList * @throws FileSystemException */ public void deleteExecutorServicesEar(String fileName, StandardFileSystemManager fsManager) throws FileSystemException { try { synchronized (urlClassLoaderMap) { ConcurrentHashMap map = (ConcurrentHashMap) filesMap.get(fileName); if (map != null) { //log.info("ClassLoader Map=\n\n\n\n"+urlClassLoaderMap); Set keysinclassloadermap = map.keySet(); System.out.println(keysinclassloadermap.size()); Iterator classloaders = keysinclassloadermap.iterator(); while (classloaders.hasNext()) { String classloader = (String) classloaders.next(); System.out.println("ClassLoader=" + classloader); ClassLoader webClassLoader = (ClassLoader) this.urlClassLoaderMap.get(map.get(classloader)); this.urlClassLoaderMap.remove(map.get(classloader)); ClassLoaderUtil.cleanupJarFileFactory(ClassLoaderUtil.closeClassLoader(webClassLoader)); urlClassLoaderMap.remove(map.get(classloader)); try { if (webClassLoader instanceof WebClassLoader) ((WebClassLoader) webClassLoader).close(); else if (webClassLoader instanceof VFSClassLoader) { FileObject[] fObj = ((VFSClassLoader) webClassLoader).getFileObjects(); for (FileObject obj : fObj) { obj.close(); } } } catch (Throwable e) { // TODO Auto-generated catch block e.printStackTrace(); } /*if (classloader.contains(deployDirectory +"/"+ fileName)) { System.out.println("removing classloader" + deployDirectory + classloader); File warDir=new File(fileName); if(warDir.exists()){ warDeployer.deleteDir(warDir); } //System.out.println("Before Remove class loader\n\n\n\n"+this.urlClassLoaderMap); //System.out.println("Remove class loader\n\n\n\n"+this.urlClassLoaderMap); }*/ } System.gc(); classloaders = keysinclassloadermap.iterator(); while (classloaders.hasNext()) { String classloader = (String) classloaders.next(); if (classloader.endsWith(".war")) { warDeployer.removeServlets((String) map.get(classloader), classloader); File warDir = new File((String) map.get(classloader)); if (warDir.exists()) { warDeployer.deleteDir(warDir); } } } log.info(this.urlClassLoaderMap); } filesMap.remove(fileName); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.seedstack.mqtt.internal.MqttPluginTest.java
/** * Test method for//from w w w . j a v a 2 s . c o m * {@link org.seedstack.mqtt.internal.MqttPlugin#init(io.nuun.kernel.api.plugin.context.InitContext)} * . */ @Test public void testInitWithoutReconnectionConfiguration(@Mocked final Configuration configuration) { final String clientName = "clientOK1"; final String[] clients = { clientName }; final Collection<Class<?>> classes = new ArrayList<Class<?>>(); MqttPlugin plugin = new MqttPlugin(); final String defaultConfigString = "xx"; new Expectations() { { application.getConfiguration(); result = configuration; configuration.subset(MQTT_PLUGIN_CONFIGURATION_PREFIX); result = configuration; configuration.isEmpty(); result = true; configuration.getStringArray(CONNECTION_CLIENTS); result = clients; configuration.getString(anyString); result = defaultConfigString; specs.get(any); result = classes; } }; new MockUp<MqttClient>() { @Mock public void $init(String serverURI, String clientId) { } }; plugin.init(initContext); MqttClientDefinition def = new MqttClientDefinition(defaultConfigString, defaultConfigString); ConcurrentHashMap<String, MqttClientDefinition> defs = Deencapsulation.getField(plugin, "mqttClientDefinitions"); Assertions.assertThat(defs).isNotEmpty(); MqttClientDefinition clientDef = defs.get(clientName); Assertions.assertThat(clientDef.getReconnectionInterval()).isEqualTo(def.getReconnectionInterval()); Assertions.assertThat(clientDef.getReconnectionMode()).isEqualTo(def.getReconnectionMode()); }
From source file:org.seedstack.mqtt.internal.MqttPluginTest.java
/** * Test method for// w w w .j a va2s. com * {@link org.seedstack.mqtt.internal.MqttPlugin#init(io.nuun.kernel.api.plugin.context.InitContext)} * . */ @Test public void testInitWithPoolConfiguration(@Mocked final Configuration configuration, @SuppressWarnings("rawtypes") @Mocked final ArrayBlockingQueue queue, @Mocked final ThreadPoolExecutor threadPoolExecutor) { final String clientName = "clientOK1"; final String[] clients = { clientName }; final Collection<Class<?>> classes = new ArrayList<Class<?>>(); MqttPlugin plugin = new MqttPlugin(); new Expectations() { { application.getConfiguration(); result = configuration; configuration.subset(anyString); result = configuration; configuration.getStringArray(CONNECTION_CLIENTS); result = clients; configuration.getString(BROKER_URI); result = "xx"; configuration.getBoolean(POOL_ENABLED, Boolean.TRUE); result = Boolean.TRUE; specs.get(any); result = classes; } }; new MockUp<MqttClient>() { @Mock public void $init(String serverURI, String clientId) throws MqttException { } }; plugin.init(initContext); ConcurrentHashMap<String, MqttClientDefinition> defs = Deencapsulation.getField(plugin, "mqttClientDefinitions"); Assertions.assertThat(defs).isNotEmpty(); MqttClientDefinition clientDef = defs.get(clientName); Assertions.assertThat(clientDef.getPoolDefinition()).isNotNull(); Assertions.assertThat(clientDef.getPoolDefinition().getThreadPoolExecutor()).isNotNull(); }
From source file:org.seedstack.mqtt.internal.MqttPluginTest.java
/** * Test method for/*from ww w. j ava 2s.com*/ * {@link org.seedstack.mqtt.internal.MqttPlugin#init(io.nuun.kernel.api.plugin.context.InitContext)} * . */ @Test public void testInitWithCustomClient(@Mocked final Configuration configuration) { final String clientName = "clientOK1"; final String defaultString = "xx"; final String[] clients = { clientName }; final Collection<Class<?>> classes = new ArrayList<Class<?>>(); MqttPlugin plugin = new MqttPlugin(); new Expectations() { { application.getConfiguration(); result = configuration; configuration.subset(anyString); result = configuration; configuration.getStringArray(CONNECTION_CLIENTS); result = clients; configuration.getString(BROKER_URI); result = defaultString; configuration.getString(RECONNECTION_MODE); result = "NONE"; configuration.getString(RECONNECTION_INTERVAL); result = "12"; specs.get(any); result = classes; } }; new MockUp<MqttClient>() { @Mock public void $init(String serverURI, String clientId) throws MqttException { } }; plugin.init(initContext); ConcurrentHashMap<String, MqttClientDefinition> defs = Deencapsulation.getField(plugin, "mqttClientDefinitions"); Assertions.assertThat(defs).isNotEmpty(); MqttClientDefinition clientDef = defs.get(clientName); Assertions.assertThat(clientDef.getReconnectionInterval()).isEqualTo(12); Assertions.assertThat(clientDef.getReconnectionMode()).isEqualTo(MqttReconnectionMode.NONE); }
From source file:org.seedstack.mqtt.internal.MqttPluginTest.java
/** * Test method for/*from w w w.j av a2 s. co m*/ * {@link org.seedstack.mqtt.internal.MqttPlugin#init(io.nuun.kernel.api.plugin.context.InitContext)} * . */ @Test public void testInitWithListener(@Mocked final Configuration configuration) { final String clientName = "clientOK1"; final String[] clients = { clientName }; final Collection<Class<?>> classes = new ArrayList<Class<?>>(); classes.add(Listener1.class); MqttPlugin plugin = new MqttPlugin(); new Expectations() { { application.getConfiguration(); result = configuration; application.substituteWithConfiguration(clientName); result = clientName; configuration.subset(anyString); result = configuration; configuration.getStringArray(CONNECTION_CLIENTS); result = clients; configuration.getString(BROKER_URI); result = "xx"; specs.get(any); result = classes; result = new ArrayList<Class<?>>(); application.substituteWithConfiguration(anyString); result = 0; } }; new MockUp<MqttClient>() { @Mock public void $init(String serverURI, String clientId) throws MqttException { } }; plugin.init(initContext); ConcurrentHashMap<String, MqttClientDefinition> defs = Deencapsulation.getField(plugin, "mqttClientDefinitions"); Assertions.assertThat(defs).isNotEmpty(); MqttClientDefinition clientDef = defs.get(clientName); Assertions.assertThat(clientDef.getListenerDefinition()).isNotNull(); Assertions.assertThat(clientDef.getListenerDefinition().getListenerClass()).isEqualTo(Listener1.class); }
From source file:org.seedstack.mqtt.internal.MqttPluginTest.java
/** * Test method for/*from w w w. ja va 2 s . c o m*/ * {@link org.seedstack.mqtt.internal.MqttPlugin#init(io.nuun.kernel.api.plugin.context.InitContext)} * . */ @Test public void testInitWithRejectHandler(@Mocked final Configuration configuration) { final String clientName = "clientOK1"; final String[] clients = { clientName }; final Collection<Class<?>> classes = new ArrayList<Class<?>>(); classes.add(MyRejectHandler.class); final Collection<Class<?>> listenerClasses = new ArrayList<Class<?>>(); final Collection<Class<?>> publisherClasses = new ArrayList<Class<?>>(); MqttPlugin plugin = new MqttPlugin(); new Expectations() { { application.getConfiguration(); result = configuration; configuration.subset(anyString); result = configuration; configuration.getStringArray(CONNECTION_CLIENTS); result = clients; application.substituteWithConfiguration(clientName); result = clientName; configuration.getString(BROKER_URI); result = "xx"; specs.get(any); result = listenerClasses; result = publisherClasses; result = classes; } }; new MockUp<MqttClient>() { @Mock public void $init(String serverURI, String clientId) throws MqttException { } }; plugin.init(initContext); ConcurrentHashMap<String, MqttClientDefinition> defs = Deencapsulation.getField(plugin, "mqttClientDefinitions"); Assertions.assertThat(defs).isNotEmpty(); MqttClientDefinition clientDef = defs.get(clientName); Assertions.assertThat(clientDef.getPoolDefinition()).isNotNull(); Assertions.assertThat(clientDef.getPoolDefinition().getRejectHandlerClass()) .isEqualTo(MyRejectHandler.class); }
From source file:org.seedstack.mqtt.internal.MqttPluginTest.java
/** * Test method for/*from w w w .j av a 2s . co m*/ * {@link org.seedstack.mqtt.internal.MqttPlugin#init(io.nuun.kernel.api.plugin.context.InitContext)} * . */ @Test public void testInitWithPublisher(@Mocked final Configuration configuration) { final String clientName = "clientOK1"; final String[] clients = { clientName }; final Collection<Class<?>> listenerClasses = new ArrayList<Class<?>>(); final Collection<Class<?>> rejectedHandlers = new ArrayList<Class<?>>(); final Collection<Class<?>> classes = new ArrayList<Class<?>>(); classes.add(PublishHandler.class); MqttPlugin plugin = new MqttPlugin(); new Expectations() { { application.getConfiguration(); result = configuration; configuration.subset(anyString); result = configuration; application.substituteWithConfiguration(clientName); result = clientName; configuration.getStringArray(CONNECTION_CLIENTS); result = clients; configuration.getString(BROKER_URI); result = "xx"; specs.get(any); result = listenerClasses; result = classes; result = rejectedHandlers; } }; new MockUp<MqttClient>() { @Mock public void $init(String serverURI, String clientId) throws MqttException { } }; plugin.init(initContext); ConcurrentHashMap<String, MqttClientDefinition> defs = Deencapsulation.getField(plugin, "mqttClientDefinitions"); Assertions.assertThat(defs).isNotEmpty(); MqttClientDefinition clientDef = defs.get("clientOK1"); Assertions.assertThat(clientDef.getPublisherDefinition()).isNotNull(); Assertions.assertThat(clientDef.getPublisherDefinition().getPublisherClass()) .isEqualTo(PublishHandler.class); }