List of usage examples for java.util.concurrent ConcurrentHashMap put
public V put(K key, V value)
From source file:com.app.server.EARDeployer.java
/** * This method configures the executor services from the jar file. * //from w ww . jav a 2 s.co m * @param jarFile * @param classList * @throws FileSystemException */ public void deployExecutorServicesEar(String earFileName, FileObject earFile) throws FileSystemException { try { log.info("EARFILE NAMEs=" + earFileName); CopyOnWriteArrayList<URL> libs = new CopyOnWriteArrayList<URL>(); CopyOnWriteArrayList<FileObject> warObjects = new CopyOnWriteArrayList<FileObject>(); CopyOnWriteArrayList<FileObject> jarObjects = new CopyOnWriteArrayList<FileObject>(); CopyOnWriteArrayList<FileObject> sarObjects = new CopyOnWriteArrayList<FileObject>(); CopyOnWriteArrayList<FileObject> rarObjects = new CopyOnWriteArrayList<FileObject>(); CopyOnWriteArrayList<FileObject> ezbObjects = new CopyOnWriteArrayList<FileObject>(); WebClassLoader customClassLoaderBaseLib = new WebClassLoader(new URL[] { earFile.getURL() }, Thread.currentThread().getContextClassLoader()); final Field factoryField = URL.class.getDeclaredField("factory"); factoryField.setAccessible(true); factoryField.set(null, new RsrcURLStreamHandlerFactory(customClassLoaderBaseLib)); //URL.setURLStreamHandlerFactory(new RsrcURLStreamHandlerFactory(customClassLoaderBaseLib)); obtainUrls(earFile, earFile, libs, warObjects, jarObjects, sarObjects, rarObjects, ezbObjects, fsManager); VFSClassLoader customClassLoader = null; for (URL earLib : libs) { customClassLoaderBaseLib.addURL(earLib); } FileObject jarFileObject; ConcurrentHashMap classLoaderPath = new ConcurrentHashMap(); filesMap.put(earFileName, classLoaderPath); for (FileObject rarFileObj : rarObjects) { //log.info(classLoader); //warDeployer.deleteDir(new File(serverConfig.getDeploydirectory()+"/"+fileName.substring(0,fileName.lastIndexOf(".war")))); mbeanServer.invoke(rarObjectName, "deploy", new Object[] { rarFileObj }, new String[] { FileObject.class.getName() }); //} } for (FileObject sarFileObj : sarObjects) { //log.info(classLoader); //warDeployer.deleteDir(new File(serverConfig.getDeploydirectory()+"/"+fileName.substring(0,fileName.lastIndexOf(".war")))); mbeanServer.invoke(sarObjectName, "deploy", new Object[] { sarFileObj, fsManager, customClassLoaderBaseLib }, new String[] { FileObject.class.getName(), StandardFileSystemManager.class.getName(), ClassLoader.class.getName() }); //} } for (FileObject ezbFileObj : ezbObjects) { //log.info(classLoader); //warDeployer.deleteDir(new File(serverConfig.getDeploydirectory()+"/"+fileName.substring(0,fileName.lastIndexOf(".war")))); mbeanServer.invoke(ezbObjectName, "deploy", new Object[] { ezbFileObj, customClassLoaderBaseLib }, new String[] { FileObject.class.getName(), VFSClassLoader.class.getName() }); //} } for (FileObject warFileObj : warObjects) { //if(warFileObj.getName().getBaseName().endsWith(".war")){ //logger.info("filePath"+filePath); String filePath = serverConfig.getDeploydirectory() + "/" + warFileObj.getName().getBaseName(); log.info(filePath); String fileName = warFileObj.getName().getBaseName(); String directoryName = fileName.substring(0, fileName.indexOf('.')); log.info(customClassLoaderBaseLib); //warDeployer.deleteDir(new File(serverConfig.getDeploydirectory()+"/"+fileName.substring(0,fileName.lastIndexOf(".war")))); new File(serverConfig.getDeploydirectory() + "/" + fileName.substring(0, fileName.lastIndexOf(".war"))).mkdirs(); log.info(serverConfig.getDeploydirectory() + "/" + fileName.substring(0, fileName.lastIndexOf(".war"))); classLoaderPath.put(warFileObj.getName().getBaseName(), serverConfig.getDeploydirectory() + "/" + fileName.substring(0, fileName.lastIndexOf(".war"))); mbeanServer.invoke(warObjectName, "extractWar", new Object[] { warFileObj, customClassLoaderBaseLib, fsManager }, new String[] { FileObject.class.getName(), WebClassLoader.class.getName(), StandardFileSystemManager.class.getName() }); //} } //URL.setURLStreamHandlerFactory(new RsrcURLStreamHandlerFactory(null)); for (FileObject jarFileObj : jarObjects) { //log.info(classLoader); //warDeployer.deleteDir(new File(serverConfig.getDeploydirectory()+"/"+fileName.substring(0,fileName.lastIndexOf(".war")))); mbeanServer.invoke(ejbObjectName, "deploy", new Object[] { new URL(jarFileObj.getURL().toURI().toString()), fsManager, customClassLoaderBaseLib }, new String[] { URL.class.getName(), StandardFileSystemManager.class.getName(), ClassLoader.class.getName() }); //} } //for (int keyCount = 0; keyCount < keys.size(); keyCount++) {} /*for (FileObject fobject : fileObjects) { fobject.close(); }*/ //log.info("Channel unlocked"); earsDeployed.add(earFile.getName().getURI()); earFile.close(); fsManager.closeFileSystem(earFile.getFileSystem()); // ClassLoaderUtil.closeClassLoader(customClassLoader); } catch (Exception ex) { log.error("Error in deploying the ear ", ex); //ex.printStackTrace(); } }
From source file:com.android.exchange.ExchangeService.java
/** * Sent by services indicating that their thread is finished; action depends on the exitStatus * of the service./* w w w .j a v a 2 s .c o m*/ * * @param svc the service that is finished */ static public void done(AbstractSyncService svc) { ExchangeService exchangeService = INSTANCE; if (exchangeService == null) return; synchronized (sSyncLock) { long mailboxId = svc.mMailboxId; // If we're no longer the syncing thread for the mailbox, just return if (!exchangeService.isRunningInServiceThread(mailboxId)) { return; } exchangeService.releaseMailbox(mailboxId); ConcurrentHashMap<Long, SyncError> errorMap = exchangeService.mSyncErrorMap; SyncError syncError = errorMap.get(mailboxId); int exitStatus = svc.mExitStatus; Mailbox m = Mailbox.restoreMailboxWithId(exchangeService, mailboxId); if (m == null) return; if (exitStatus != AbstractSyncService.EXIT_LOGIN_FAILURE) { long accountId = m.mAccountKey; Account account = Account.restoreAccountWithId(exchangeService, accountId); if (account == null) return; if (exchangeService.releaseSyncHolds(exchangeService, AbstractSyncService.EXIT_LOGIN_FAILURE, account)) { new AccountServiceProxy(exchangeService).notifyLoginSucceeded(accountId); } } switch (exitStatus) { case AbstractSyncService.EXIT_DONE: if (svc.hasPendingRequests()) { // TODO Handle this case } errorMap.remove(mailboxId); // If we've had a successful sync, clear the shutdown count synchronized (ExchangeService.class) { sClientConnectionManagerShutdownCount = 0; } break; // I/O errors get retried at increasing intervals case AbstractSyncService.EXIT_IO_ERROR: if (syncError != null) { syncError.escalate(); log(m.mDisplayName + " held for " + syncError.holdDelay + "ms"); } else { errorMap.put(mailboxId, exchangeService.new SyncError(exitStatus, false)); log(m.mDisplayName + " added to syncErrorMap, hold for 15s"); } break; // These errors are not retried automatically case AbstractSyncService.EXIT_LOGIN_FAILURE: new AccountServiceProxy(exchangeService).notifyLoginFailed(m.mAccountKey); // Fall through case AbstractSyncService.EXIT_SECURITY_FAILURE: case AbstractSyncService.EXIT_ACCESS_DENIED: case AbstractSyncService.EXIT_EXCEPTION: errorMap.put(mailboxId, exchangeService.new SyncError(exitStatus, true)); break; } kick("sync completed"); } }
From source file:com.web.server.EARDeployer.java
public void obtainUrls(FileObject rootEar, FileObject ear, CopyOnWriteArrayList<FileObject> fileObjects, ConcurrentHashMap jarclassListMap, CopyOnWriteArrayList<FileObject> warObjects, StandardFileSystemManager fsManager) throws IOException { FileObject[] childrenJars = ear.getChildren(); for (int childcount = 0; childcount < childrenJars.length; childcount++) { if (childrenJars[childcount].getType() == FileType.FOLDER) { obtainUrls(rootEar, childrenJars[childcount], fileObjects, jarclassListMap, warObjects, fsManager); }/* w w w .j av a2s . co m*/ // System.out.println(childrenJars[childcount]); // System.out.println(childrenJars[childcount].getName().getBaseName()); // System.out.println(ear.getURL()); if (childrenJars[childcount].getType() == FileType.FILE && (childrenJars[childcount].getName().getBaseName().endsWith(".jar") || childrenJars[childcount].getName().getBaseName().endsWith(".war"))) { // System.out.println(childrenJars[childcount].getURL()); if (childrenJars[childcount].getName().getBaseName().endsWith(".war")) { File file = new File(scanDirectory + "/" + childrenJars[childcount].getName().getBaseName()); if (!file.exists() || (file.exists() && file.lastModified() != childrenJars[childcount] .getContent().getLastModifiedTime())) { InputStream fistr = childrenJars[childcount].getContent().getInputStream(); byte[] filyByt = new byte[4096]; FileOutputStream warFile = new FileOutputStream( scanDirectory + "/" + childrenJars[childcount].getName().getBaseName()); int len = 0; while ((len = fistr.read(filyByt)) != -1) { warFile.write(filyByt, 0, len); } warFile.close(); fistr.close(); warObjects.add(childrenJars[childcount]); } } // System.out.println(childrenJars[childcount].getURL().toString()+" "+rootEar.getURL()); else if (!childrenJars[childcount].getURL().toString().trim() .startsWith(rootEar.getURL().toString() + "lib/")) { CopyOnWriteArrayList<String> classList = new CopyOnWriteArrayList<String>(); getClassList(childrenJars[childcount], classList, fsManager); jarclassListMap.put(childrenJars[childcount], classList); } else { System.out.println("ear libs/" + childrenJars[childcount]); fileObjects.add(childrenJars[childcount]); } } else { childrenJars[childcount].close(); } } }
From source file:org.wso2.carbon.event.output.adapter.core.internal.CarbonOutputEventAdapterService.java
@Override public void create(OutputEventAdapterConfiguration outputEventAdapterConfiguration) throws OutputEventAdapterException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); ConcurrentHashMap<String, OutputAdapterRuntime> eventAdapters = tenantSpecificEventAdapters.get(tenantId); if (eventAdapters == null) { tenantSpecificEventAdapters.putIfAbsent(tenantId, new ConcurrentHashMap<String, OutputAdapterRuntime>()); eventAdapters = tenantSpecificEventAdapters.get(tenantId); }/*from w ww . j av a2 s .co m*/ OutputEventAdapterFactory adapterFactory = eventAdapterFactoryMap .get(outputEventAdapterConfiguration.getType()); if (adapterFactory == null) { throw new OutputEventAdapterException( "Output Event Adapter not created as no adapter factory is registered " + "with type " + outputEventAdapterConfiguration.getType()); } if (outputEventAdapterConfiguration.getName() == null) { throw new OutputEventAdapterException("Output Event Adapter name cannot by null, for the adapter type " + outputEventAdapterConfiguration.getType()); } if (eventAdapters.get(outputEventAdapterConfiguration.getName()) != null) { throw new OutputEventAdapterException( "Output Event Adapter not created as another adapter with same name '" + outputEventAdapterConfiguration.getName() + "' already exist for tenant " + tenantId); } //check if all the required properties are given here List<Property> staticPropertyList = adapterFactory.getStaticPropertyList(); if (staticPropertyList != null) { Map<String, String> staticPropertyMap = outputEventAdapterConfiguration.getStaticProperties(); for (Property property : staticPropertyList) { if (property.isRequired()) { if (staticPropertyMap == null) { throw new OutputEventAdapterException( "Output Event Adapter not created as the 'staticProperties' are null, " + "which means, the required property " + property.getPropertyName() + " is not being set, for the adapter type " + outputEventAdapterConfiguration.getType()); } if (staticPropertyMap.get(property.getPropertyName()) == null) { throw new OutputEventAdapterException( "Output Event Adapter not created as the required property: " + property.getPropertyName() + " is not set, for the adapter type " + outputEventAdapterConfiguration.getType()); } } } } Map<String, String> globalProperties = OutputEventAdapterServiceValueHolder.getGlobalAdapterConfigs() .getAdapterConfig(outputEventAdapterConfiguration.getType()).getGlobalPropertiesAsMap(); eventAdapters.put(outputEventAdapterConfiguration.getName(), new OutputAdapterRuntime( adapterFactory.createEventAdapter(outputEventAdapterConfiguration, globalProperties), outputEventAdapterConfiguration.getName())); }
From source file:com.web.server.SARDeployer.java
/** * This method is the implementation of the SAR deployer *//*from w ww.j a v a2 s . co m*/ public void run() { String filePath; FileInfo fileinfoTmp; ConcurrentHashMap filePrevMap = new ConcurrentHashMap(); ConcurrentHashMap fileCurrMap = new ConcurrentHashMap(); ; FileInfo filePrevLastModified; FileInfo fileCurrLastModified; DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() { protected void loadRules() { // TODO Auto-generated method stub try { loadXMLRules(new InputSource(new FileInputStream("./config/sar-config.xml"))); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); sardigester = serverdigesterLoader.newDigester(); while (true) { try { File file = new File(deployDirectory); File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) continue; //Long lastModified=(Long) fileMap.get(files[i].getName()); if (files[i].getName().toLowerCase().endsWith(".sar")) { filePath = files[i].getAbsolutePath(); //logger.info("filePath"+filePath); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".sar")); File sarDirectory = new File(filePath + "sar"); fileinfoTmp = new FileInfo(); fileinfoTmp.setFile(files[i]); fileinfoTmp.setLastModified(files[i].lastModified()); if (!sarDirectory.exists() || fileCurrMap.get(files[i].getName()) == null && filePrevMap.get(files[i].getName()) == null) { if (sarDirectory.exists()) { deleteDir(sarDirectory); } try { extractSar(files[i], sarDirectory.getAbsolutePath()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //System.out.println("War Deployed Successfully in path: "+filePath); numberOfSarDeployed++; logger.info(files[i] + " Deployed"); sarsDeployed.add(files[i].getName()); filePrevMap.put(files[i].getName(), fileinfoTmp); } fileCurrMap.put(files[i].getName(), fileinfoTmp); } /*if(lastModified==null||lastModified!=files[i].lastModified()){ fileMap.put(files[i].getName(),files[i].lastModified()); }*/ } Set keyset = fileCurrMap.keySet(); Iterator ite = keyset.iterator(); String fileName; while (ite.hasNext()) { fileName = (String) ite.next(); //logger.info("fileName"+fileName); filePrevLastModified = (FileInfo) filePrevMap.get(fileName); fileCurrLastModified = (FileInfo) fileCurrMap.get(fileName); if (filePrevLastModified != null) //logger.info("lastmodified="+filePrevLastModified.getLastModified()); //System.out.println("prevmodified"+fileCurrLastModified.getLastModified()+""+filePrevLastModified.getLastModified()); if (fileCurrLastModified != null) { //System.out.println("prevmodified"+fileCurrLastModified.getLastModified()); } if (filePrevLastModified == null || filePrevLastModified.getLastModified() != fileCurrLastModified.getLastModified()) { filePath = fileCurrLastModified.getFile().getAbsolutePath(); //logger.info("filePath"+filePath); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".sar")); File sarDirectory = new File(filePath + "sar"); //logger.info("WARDIRECTORY="+warDirectory.getAbsolutePath()); if (sarDirectory.exists() && sarDirectory.isDirectory()) { deleteDir(sarDirectory); sarsDeployed.remove(fileName); numberOfSarDeployed--; } try { extractSar(fileCurrLastModified.getFile(), sarDirectory.getAbsolutePath()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //System.out.println("War Deployed Successfully in path: "+fileCurrLastModified.getFile().getAbsolutePath()); numberOfSarDeployed++; sarsDeployed.add(fileName); logger.info(filePath + ".sar Deployed"); } } keyset = filePrevMap.keySet(); ite = keyset.iterator(); while (ite.hasNext()) { fileName = (String) ite.next(); filePrevLastModified = (FileInfo) filePrevMap.get(fileName); fileCurrLastModified = (FileInfo) fileCurrMap.get(fileName); if (fileCurrLastModified == null) { filePath = filePrevLastModified.getFile().getAbsolutePath(); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".sar")); logger.info("filePath" + filePath); File deleteDirectory = new File(filePath + "sar"); deleteDir(deleteDirectory); numberOfSarDeployed--; sarsDeployed.remove(fileName); logger.info(filePath + ".sar Undeployed"); } } filePrevMap.keySet().removeAll(filePrevMap.keySet()); filePrevMap.putAll(fileCurrMap); fileCurrMap.keySet().removeAll(fileCurrMap.keySet()); //System.out.println("filePrevMap="+filePrevMap); //System.out.println("fileCurrMap="+fileCurrMap); try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (Exception ex) { ex.printStackTrace(); System.out.println("Sar Deployed"); } } }
From source file:org.wso2.carbon.event.input.adaptor.jms.JMSEventAdaptorType.java
private void createJMSAdaptorListener( InputEventAdaptorMessageConfiguration inputEventAdaptorMessageConfiguration, InputEventAdaptorListener inputEventAdaptorListener, InputEventAdaptorConfiguration inputEventAdaptorConfiguration, AxisConfiguration axisConfiguration, String subscriptionId, int tenantId) { ConcurrentHashMap<String, ConcurrentHashMap<String, ConcurrentHashMap<String, SubscriptionDetails>>> adaptorDestinationSubscriptionsMap = tenantAdaptorDestinationSubscriptionsMap .get(tenantId);/*from ww w. j a v a 2 s . co m*/ if (adaptorDestinationSubscriptionsMap == null) { adaptorDestinationSubscriptionsMap = new ConcurrentHashMap<String, ConcurrentHashMap<String, ConcurrentHashMap<String, SubscriptionDetails>>>(); if (null != tenantAdaptorDestinationSubscriptionsMap.putIfAbsent(tenantId, adaptorDestinationSubscriptionsMap)) { adaptorDestinationSubscriptionsMap = tenantAdaptorDestinationSubscriptionsMap.get(tenantId); } } ConcurrentHashMap<String, ConcurrentHashMap<String, SubscriptionDetails>> destinationSubscriptionsMap = adaptorDestinationSubscriptionsMap .get(inputEventAdaptorConfiguration.getName()); if (destinationSubscriptionsMap == null) { destinationSubscriptionsMap = new ConcurrentHashMap<String, ConcurrentHashMap<String, SubscriptionDetails>>(); if (null != adaptorDestinationSubscriptionsMap.putIfAbsent(inputEventAdaptorConfiguration.getName(), destinationSubscriptionsMap)) { destinationSubscriptionsMap = adaptorDestinationSubscriptionsMap .get(inputEventAdaptorConfiguration.getName()); } } String destination = inputEventAdaptorMessageConfiguration.getInputMessageProperties() .get(JMSEventAdaptorConstants.ADAPTOR_JMS_DESTINATION); ConcurrentHashMap<String, SubscriptionDetails> subscriptionsMap = destinationSubscriptionsMap .get(destination); if (subscriptionsMap == null) { subscriptionsMap = new ConcurrentHashMap<String, SubscriptionDetails>(); if (null != destinationSubscriptionsMap.putIfAbsent(destination, subscriptionsMap)) { subscriptionsMap = destinationSubscriptionsMap.get(destination); } } Map<String, String> adaptorProperties = new HashMap<String, String>(); if (inputEventAdaptorConfiguration.getInputProperties() .get(JMSEventAdaptorConstants.ADAPTOR_JMS_DURABLE_SUBSCRIBER_NAME) != null) { InternalInputEventAdaptorConfiguration internalInputEventAdaptorConfiguration = inputEventAdaptorConfiguration .getInputConfiguration(); internalInputEventAdaptorConfiguration .addEventAdaptorProperty(JMSEventAdaptorConstants.ADAPTOR_JMS_SUBSCRIPTION_DURABLE, "true"); inputEventAdaptorConfiguration.setInputConfiguration(internalInputEventAdaptorConfiguration); } else { InternalInputEventAdaptorConfiguration internalInputEventAdaptorConfiguration = inputEventAdaptorConfiguration .getInputConfiguration(); internalInputEventAdaptorConfiguration .addEventAdaptorProperty(JMSEventAdaptorConstants.ADAPTOR_JMS_SUBSCRIPTION_DURABLE, "false"); inputEventAdaptorConfiguration.setInputConfiguration(internalInputEventAdaptorConfiguration); } adaptorProperties.putAll(inputEventAdaptorConfiguration.getInputProperties()); JMSConnectionFactory jmsConnectionFactory = new JMSConnectionFactory( new Hashtable<String, String>(adaptorProperties), inputEventAdaptorConfiguration.getName()); Map<String, String> messageConfig = new HashMap<String, String>(); messageConfig.put(JMSConstants.PARAM_DESTINATION, destination); JMSTaskManager jmsTaskManager = JMSTaskManagerFactory .createTaskManagerForService( jmsConnectionFactory, inputEventAdaptorConfiguration.getName(), new NativeWorkerPool(4, 100, 1000, 1000, "JMS Threads", "JMSThreads" + UUID.randomUUID().toString()), messageConfig); jmsTaskManager.setJmsMessageListener(new JMSMessageListener(inputEventAdaptorListener, axisConfiguration)); JMSListener jmsListener = new JMSListener(inputEventAdaptorConfiguration.getName() + "#" + destination, jmsTaskManager); jmsListener.startListener(); SubscriptionDetails subscriptionDetails = new SubscriptionDetails(jmsConnectionFactory, jmsListener); subscriptionsMap.put(subscriptionId, subscriptionDetails); }
From source file:com.web.server.WarDeployer.java
/** * This method is the implementation of the war deployer which frequently scans the deploy * directory and if there is a change in war redeploys and configures the map *//*w ww.ja v a 2s .c o m*/ public void run() { File file; ConcurrentHashMap filePrevMap = new ConcurrentHashMap(); ConcurrentHashMap fileCurrMap = new ConcurrentHashMap(); ; FileInfo filePrevLastModified; FileInfo fileCurrLastModified; String filePath; FileInfo fileinfoTmp; URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader(); URL[] urls = loader.getURLs(); warsDeployed = new CopyOnWriteArrayList(); //System.out.println("URLS="+urls[0]); WebClassLoader customClassLoader; while (true) { file = new File(scanDirectory); File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) continue; //Long lastModified=(Long) fileMap.get(files[i].getName()); if (files[i].getName().endsWith(".war")) { filePath = files[i].getAbsolutePath(); //logger.info("filePath"+filePath); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".war")); File warDirectory = new File(filePath); fileinfoTmp = new FileInfo(); fileinfoTmp.setFile(files[i]); fileinfoTmp.setLastModified(files[i].lastModified()); if (!warDirectory.exists() || fileCurrMap.get(files[i].getName()) == null && filePrevMap.get(files[i].getName()) == null) { if (warDirectory.exists()) { deleteDir(warDirectory); } customClassLoader = new WebClassLoader(urls); synchronized (urlClassLoaderMap) { logger.info("WARDIRECTORY=" + warDirectory.getAbsolutePath()); urlClassLoaderMap.put(warDirectory.getAbsolutePath().replace("\\", "/"), customClassLoader); } extractWar(files[i], customClassLoader); //System.out.println("War Deployed Successfully in path: "+filePath); AddUrlToClassLoader(warDirectory, customClassLoader); numberOfWarDeployed++; logger.info(files[i] + " Deployed"); warsDeployed.add(files[i].getName()); filePrevMap.put(files[i].getName(), fileinfoTmp); } fileCurrMap.put(files[i].getName(), fileinfoTmp); } /*if(lastModified==null||lastModified!=files[i].lastModified()){ fileMap.put(files[i].getName(),files[i].lastModified()); }*/ } Set keyset = fileCurrMap.keySet(); Iterator ite = keyset.iterator(); String fileName; while (ite.hasNext()) { fileName = (String) ite.next(); //logger.info("fileName"+fileName); filePrevLastModified = (FileInfo) filePrevMap.get(fileName); fileCurrLastModified = (FileInfo) fileCurrMap.get(fileName); if (filePrevLastModified != null) //logger.info("lastmodified="+filePrevLastModified.getLastModified()); //System.out.println("prevmodified"+fileCurrLastModified.getLastModified()+""+filePrevLastModified.getLastModified()); if (fileCurrLastModified != null) { //System.out.println("prevmodified"+fileCurrLastModified.getLastModified()); } if (filePrevLastModified == null || filePrevLastModified.getLastModified() != fileCurrLastModified.getLastModified()) { filePath = fileCurrLastModified.getFile().getAbsolutePath(); //logger.info("filePath"+filePath); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".war")); File warDirectory = new File(filePath); //logger.info("WARDIRECTORY="+warDirectory.getAbsolutePath()); if (warDirectory.exists()) { WebClassLoader webClassLoader = (WebClassLoader) urlClassLoaderMap .get(warDirectory.getAbsolutePath().replace("\\", "/")); synchronized (executorServiceMap) { try { new ExecutorServicesConstruct().removeExecutorServices(executorServiceMap, new File(warDirectory.getAbsolutePath().replace("\\", "/") + "/WEB-INF/" + "executorservices.xml"), webClassLoader); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //System.out.println("executorServiceMap"+executorServiceMap); } synchronized (messagingClassMap) { try { new MessagingClassConstruct().removeMessagingClass(messagedigester, new File(warDirectory.getAbsolutePath().replace("\\", "/") + "/WEB-INF/" + "messagingclass.xml"), messagingClassMap); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("executorServiceMap" + executorServiceMap); } ClassLoaderUtil.cleanupJarFileFactory(ClassLoaderUtil.closeClassLoader(webClassLoader)); try { webClassLoader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } logger.info("ServletMapping" + servletMapping); logger.info("warDirectory=" + warDirectory.getAbsolutePath().replace("\\", "/")); urlClassLoaderMap.remove(warDirectory.getAbsolutePath().replace("\\", "/")); WebAppConfig webAppConfig = (WebAppConfig) servletMapping .remove(warDirectory.getAbsolutePath().replace("\\", "/")); System.gc(); deleteDir(warDirectory); warsDeployed.remove(fileName); removeServletFromSessionObject(webAppConfig, warDirectory.getAbsolutePath().replace("\\", "/")); numberOfWarDeployed--; } customClassLoader = new WebClassLoader(urls); logger.info(customClassLoader); urlClassLoaderMap.put(warDirectory.getAbsolutePath().replace("\\", "/"), customClassLoader); extractWar(fileCurrLastModified.getFile(), customClassLoader); //System.out.println("War Deployed Successfully in path: "+fileCurrLastModified.getFile().getAbsolutePath()); AddUrlToClassLoader(warDirectory, customClassLoader); numberOfWarDeployed++; warsDeployed.add(fileName); logger.info(filePath + ".war Deployed"); } } keyset = filePrevMap.keySet(); ite = keyset.iterator(); while (ite.hasNext()) { fileName = (String) ite.next(); filePrevLastModified = (FileInfo) filePrevMap.get(fileName); fileCurrLastModified = (FileInfo) fileCurrMap.get(fileName); if (fileCurrLastModified == null) { filePath = filePrevLastModified.getFile().getAbsolutePath(); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".war")); logger.info("filePath" + filePath); File deleteDirectory = new File(filePath); logger.info("Delete Directory" + deleteDirectory.getAbsolutePath().replace("\\", "/")); WebClassLoader webClassLoader = (WebClassLoader) urlClassLoaderMap .get(deleteDirectory.getAbsolutePath().replace("\\", "/")); ; synchronized (executorServiceMap) { try { new ExecutorServicesConstruct().removeExecutorServices(executorServiceMap, new File(deleteDirectory.getAbsolutePath().replace("\\", "/") + "/WEB-INF/" + "executorservices.xml"), webClassLoader); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //System.out.println("executorServiceMap"+executorServiceMap); } synchronized (messagingClassMap) { try { new MessagingClassConstruct().removeMessagingClass(messagedigester, new File(deleteDirectory.getAbsolutePath().replace("\\", "/") + "/WEB-INF/" + "messagingclass.xml"), messagingClassMap); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //System.out.println("executorServiceMap"+executorServiceMap); } WebAppConfig webAppConfig = (WebAppConfig) servletMapping .remove(deleteDirectory.getAbsolutePath().replace("\\", "/")); ClassLoaderUtil.cleanupJarFileFactory(ClassLoaderUtil.closeClassLoader(webClassLoader)); urlClassLoaderMap.remove(deleteDirectory.getAbsolutePath().replace("\\", "/")); logger.info("ServletMapping" + servletMapping); logger.info("warDirectory=" + deleteDirectory.getAbsolutePath().replace("\\", "/")); try { logger.info(webClassLoader); logger.info("CLASSLOADER IS CLOSED"); webClassLoader.close(); } catch (Throwable e) { // TODO Auto-generated catch block e.printStackTrace(); } System.gc(); deleteDir(deleteDirectory); numberOfWarDeployed--; warsDeployed.remove(fileName); try { removeServletFromSessionObject(webAppConfig, deleteDirectory.getAbsolutePath().replace("\\", "/")); } catch (Exception ex) { ex.printStackTrace(); } logger.info(filePath + ".war Undeployed"); } } filePrevMap.keySet().removeAll(filePrevMap.keySet()); filePrevMap.putAll(fileCurrMap); fileCurrMap.keySet().removeAll(fileCurrMap.keySet()); //System.out.println("filePrevMap="+filePrevMap); //System.out.println("fileCurrMap="+fileCurrMap); try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:com.app.server.WarDeployer.java
/** * This method deploys the war in exploded form and configures it. * //from w w w .j a va2 s.c o m * @param file * @param customClassLoader * @param warDirectoryPath */ public void extractWar(File file, ClassLoader classLoader) { StringBuffer classPath = new StringBuffer(); int numBytes; WebClassLoader customClassLoader = null; CopyOnWriteArrayList<URL> jarUrls = new CopyOnWriteArrayList<URL>(); try { ConcurrentHashMap jspMap = new ConcurrentHashMap(); ZipFile zip = new ZipFile(file); ZipEntry ze = null; // String fileName=file.getName(); String directoryName = file.getName(); directoryName = directoryName.substring(0, directoryName.indexOf('.')); try { /*ClassLoader classLoader = Thread.currentThread() .getContextClassLoader();*/ // log.info("file://"+warDirectoryPath+"/WEB-INF/classes/"); jarUrls.add(new URL("file:" + scanDirectory + "/" + directoryName + "/WEB-INF/classes/")); // new WebServer().addURL(new // URL("file://"+warDirectoryPath+"/"),customClassLoader); } catch (Exception e) { log.error("syntax of the URL is incorrect", e); //e1.printStackTrace(); } String fileDirectory; Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ze = entries.nextElement(); // //log.info("Unzipping " + ze.getName()); String filePath = scanDirectory + "/" + directoryName + "/" + ze.getName(); if (!ze.isDirectory()) { fileDirectory = filePath.substring(0, filePath.lastIndexOf('/')); } else { fileDirectory = filePath; } // //log.info(fileDirectory); createDirectory(fileDirectory); if (!ze.isDirectory()) { FileOutputStream fout = new FileOutputStream(filePath); byte[] inputbyt = new byte[8192]; InputStream istream = zip.getInputStream(ze); while ((numBytes = istream.read(inputbyt, 0, inputbyt.length)) >= 0) { fout.write(inputbyt, 0, numBytes); } fout.close(); istream.close(); if (ze.getName().endsWith(".jsp")) { jspMap.put(ze.getName(), filePath); } else if (ze.getName().endsWith(".jar")) { jarUrls.add(new URL("file:///" + scanDirectory + "/" + directoryName + "/" + ze.getName())); classPath.append(filePath); classPath.append(";"); } } } zip.close(); Set jsps = jspMap.keySet(); Iterator jspIterator = jsps.iterator(); classPath.append(scanDirectory + "/" + directoryName + "/WEB-INF/classes;"); jarUrls.add(new URL("file:" + scanDirectory + "/" + directoryName + "/WEB-INF/classes/;")); ArrayList<String> jspFiles = new ArrayList(); // log.info(classPath.toString()); if (jspIterator.hasNext()) { jarUrls.add(new URL("file:" + scanDirectory + "/temp/" + directoryName + "/")); customClassLoader = new WebClassLoader(jarUrls.toArray(new URL[jarUrls.size()]), classLoader); while (jspIterator.hasNext()) { String filepackageInternal = (String) jspIterator.next(); String filepackageInternalTmp = filepackageInternal; if (filepackageInternal.lastIndexOf('/') == -1) { filepackageInternal = ""; } else { filepackageInternal = filepackageInternal.substring(0, filepackageInternal.lastIndexOf('/')) .replace("/", "."); filepackageInternal = "." + filepackageInternal; } createDirectory(scanDirectory + "/temp/" + directoryName); File jspFile = new File((String) jspMap.get(filepackageInternalTmp)); String fName = jspFile.getName(); String fileNameWithoutExtension = fName.substring(0, fName.lastIndexOf(".jsp")) + "_jsp"; // String fileCreated=new JspCompiler().compileJsp((String) // jspMap.get(filepackageInternalTmp), // scanDirectory+"/temp/"+fileName, // "com.app.server"+filepackageInternal,classPath.toString()); synchronized (customClassLoader) { String fileNameInWar = filepackageInternalTmp; jspFiles.add(fileNameInWar.replace("/", "\\")); if (fileNameInWar.contains("/") || fileNameInWar.contains("\\")) { customClassLoader.addURL("/" + fileNameInWar.replace("\\", "/"), "com.app.server" + filepackageInternal.replace("WEB-INF", "WEB_002dINF") + "." + fileNameWithoutExtension); } else { customClassLoader.addURL("/" + fileNameInWar, "com.app.server" + filepackageInternal.replace("WEB-INF", "WEB_002dINF") + "." + fileNameWithoutExtension); } } } } else { customClassLoader = new WebClassLoader(jarUrls.toArray(new URL[jarUrls.size()]), classLoader); } String filePath = file.getAbsolutePath(); // log.info("filePath"+filePath); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".war")); urlClassLoaderMap.put(filePath.replace("\\", "/"), customClassLoader); if (jspFiles.size() > 0) { ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); //Thread.currentThread().setContextClassLoader(customClassLoader); String classPathBefore = ""; try { JspCompiler jspc = new JspCompiler(); jspc.setUriroot(scanDirectory + "/" + directoryName); jspc.setAddWebXmlMappings(false); jspc.setListErrors(false); jspc.setCompile(true); jspc.setOutputDir(scanDirectory + "/temp/" + directoryName + "/"); jspc.setPackage("com.app.server"); StringBuffer buffer = new StringBuffer(); for (String jspFile : jspFiles) { buffer.append(","); buffer.append(jspFile); } String jsp = buffer.toString(); jsp = jsp.substring(1, jsp.length()); //log.info(jsp); classPathBefore = System.getProperty("java.class.path"); System.setProperty("java.class.path", System.getProperty("java.class.path") + ";" + classPath.toString().replace("/", "\\")); //jspc.setClassPath(System.getProperty("java.class.path")+";"+classPath.toString().replace("/", "\\")); jspc.setJspFiles(jsp); jspc.initCL(customClassLoader); jspc.execute(); //jspc.closeClassLoader(); //jspc.closeClassLoader(); } catch (Throwable je) { log.error("Error in compiling the jsp page", je); //je.printStackTrace(); } finally { System.setProperty("java.class.path", classPathBefore); //Thread.currentThread().setContextClassLoader(oldCL); } //Thread.currentThread().setContextClassLoader(customClassLoader); } try { File execxml = new File(scanDirectory + "/" + directoryName + "/WEB-INF/" + "executorservices.xml"); if (execxml.exists()) { new ExecutorServicesConstruct().getExecutorServices(serverdigester, executorServiceMap, execxml, customClassLoader); } } catch (Exception e) { log.error("error in getting executor services ", e); // e.printStackTrace(); } try { File messagingxml = new File( scanDirectory + "/" + directoryName + "/WEB-INF/" + "messagingclass.xml"); if (messagingxml.exists()) { new MessagingClassConstruct().getMessagingClass(messagedigester, messagingxml, customClassLoader, messagingClassMap); } } catch (Exception e) { log.error("Error in getting the messaging classes ", e); // e.printStackTrace(); } webxmldigester.setNamespaceAware(true); webxmldigester.setValidating(true); // digester.setRules(null); FileInputStream webxml = new FileInputStream( scanDirectory + "/" + directoryName + "/WEB-INF/" + "web.xml"); InputSource is = new InputSource(webxml); try { //log.info("SCHEMA"); synchronized (webxmldigester) { // webxmldigester.set("config/web-app_2_4.xsd"); WebAppConfig webappConfig = (WebAppConfig) webxmldigester.parse(is); servletMapping.put(scanDirectory + "/" + directoryName.replace("\\", "/"), webappConfig); } webxml.close(); } catch (Exception e) { log.error("Error in pasrsing the web.xml", e); //e.printStackTrace(); } //customClassLoader.close(); // ClassLoaderUtil.closeClassLoader(customClassLoader); } catch (Exception ex) { log.error("Error in Deploying war " + file.getAbsolutePath(), ex); } }
From source file:com.flexoodb.common.FlexUtils.java
static public String getRDBMSRecordAsXML(String tablename, RecordSet rec, String idcolumn, String parentidcolumn, boolean includeidcolumns, boolean listall) throws Exception { StringBuffer res = new StringBuffer(); int size = rec.size(); if (size > 0) { // first we get the table struc Enumeration en = rec.getColumnNames(); ConcurrentHashMap<String, String> columns = new ConcurrentHashMap<String, String>(); while (en.hasMoreElements()) { String cname = (String) en.nextElement(); String type = rec.getColumnType(cname); columns.put(cname.toLowerCase(), type); }// w ww .j a v a 2 s . c o m boolean done = false; int i = 0; while (i < rec.size() && !done) { res.append("<" + tablename + ">"); en = columns.keys(); while (en.hasMoreElements()) { String cname = ((String) en.nextElement()).toLowerCase(); String type = columns.get(cname); boolean readrec = includeidcolumns; if (!readrec) { readrec = (!cname.equalsIgnoreCase(idcolumn) && !cname.equalsIgnoreCase(parentidcolumn)); } if (readrec) { if (type.toUpperCase().indexOf("BLOB") > -1 || type.toUpperCase().indexOf("BINARY") > -1) { Object o = rec.getContent(cname); if (o instanceof com.mysql.jdbc.Blob) { //byte[] b = BufferedInputStreamToString(((com.mysql.jdbc.Blob)o).getBinaryStream()).getBytes(); Blob blob = ((Blob) o); byte[] b = blob.getBytes(1, (int) blob.length()); res.append("<" + cname + " type=\"byte[]\"><![CDATA[" + new String(b) + "]]></" + cname + ">"); } else { res.append("<" + cname + " type=\"byte[]\"><![CDATA[" + o + "]]></" + cname + ">"); } } else if (type.indexOf("CHAR") > -1 || type.indexOf("TEXT") > -1) { res.append("<" + cname + " type=\"String\"><![CDATA[" + stripNonValidChars(rec.getString(cname)) + "]]></" + cname + ">"); } else if (type.equalsIgnoreCase("DATE") || type.equalsIgnoreCase("DATETIME") || type.equalsIgnoreCase("TIMESTAMP") || (type != null && type.toUpperCase().equals("YEAR"))) { res.append("<" + cname + " type=\"XMLGregorianCalendar\"><![CDATA[" + rec.getString(cname) + "]]></" + cname + ">"); } else if (type.equalsIgnoreCase("LONG") || type.equalsIgnoreCase("TINY") || type.equalsIgnoreCase("BIT") || type.equalsIgnoreCase("BIGINT") || type.equalsIgnoreCase("SMALLINT") || type.equalsIgnoreCase("TINYINT") || type.equalsIgnoreCase("MEDIUMINT") || type.equalsIgnoreCase("INT")) { res.append("<" + cname + " type=\"BigInteger\"><![CDATA[" + rec.getInt(cname) + "]]></" + cname + ">"); } else if (type.equalsIgnoreCase("DOUBLE") || type.equalsIgnoreCase("NUMERIC") || type.equalsIgnoreCase("DECIMAL")) { res.append("<" + cname + " type=\"Double\"><![CDATA[" + rec.getDouble(cname) + "]]></" + cname + ">"); } else if (type.equalsIgnoreCase("FLOAT")) { res.append("<" + cname + " type=\"Float\"><![CDATA[" + rec.getFloat(cname) + "]]></" + cname + ">"); } /*else if (type.equalsIgnoreCase("LONG")) { res.append("<"+proper(cname)+" type=\"Long\"><![CDATA["+rec.getDouble(cname)+"]]></"+proper(cname)+">"); }*/ else { //res.append("<"+proper(cname)+" type=\""+cname+"\"><![CDATA["+rec.getString(cname)+"]]></"+proper(cname)+">"); throw new Exception(cname + " type " + type + " is not recognized."); } } } res.append("</" + tablename + ">\n"); if (!listall) { done = true; } else { i++; rec.next(); } } } return new String(res.substring(0).getBytes("UTF8")); }
From source file:com.flexoodb.common.FlexUtils.java
static public String getRDBMSRecordAsXML(String tablename, RecordSet rec, String idcolumn, String parentidcolumn, boolean includeidcolumns, FlexElement idelement) throws Exception { StringBuffer res = new StringBuffer(); int size = rec.size(); if (size > 0) { // first we get the table struc Enumeration en = rec.getColumnNames(); ConcurrentHashMap<String, String> columns = new ConcurrentHashMap<String, String>(); while (en.hasMoreElements()) { String cname = (String) en.nextElement(); String type = rec.getColumnType(cname); columns.put(cname.toLowerCase(), type); }//from w w w. jav a 2s . c o m res.append("<" + tablename + ">"); en = columns.keys(); String cname = ""; FlexElement aliascolumn = null; while (en.hasMoreElements()) { aliascolumn = null; cname = ""; cname = (String) en.nextElement(); String objectField = ""; aliascolumn = (FlexElement) idelement.getElementByName(cname.trim(), false); if (aliascolumn == null) { objectField = cname; } else { if (aliascolumn.getAttribute("alias") == null) { objectField = cname; } else { objectField = aliascolumn.getAttribute("alias").getValue(); } } String type = columns.get(cname); boolean readrec = includeidcolumns; if (!readrec) { readrec = (!cname.equalsIgnoreCase(idcolumn) && !cname.equalsIgnoreCase(parentidcolumn)); } if (readrec) { if (type.toUpperCase().indexOf("BLOB") > -1 || type.toUpperCase().indexOf("BINARY") > -1) { Object o = rec.getContent(cname); if (o != null) { //System.out.print(cname+")type:"+type+" "+o.getClass()); Blob blob = ((Blob) o); byte[] b = blob.getBytes(1, (int) blob.length()); res.append("<" + objectField + " type=\"byte[]\"><![CDATA[" + new String(b) + "]]></" + objectField + ">"); } else { res.append("<" + objectField + " type=\"byte[]\"><![CDATA[]]></" + objectField + ">"); } } else if (type.indexOf("CHAR") > -1 || type.indexOf("TEXT") > -1 || type.toUpperCase().equals("YEAR")) { res.append("<" + objectField + " type=\"String\"><![CDATA[" + rec.getString(cname) + "]]></" + objectField + ">"); } else if (type.equalsIgnoreCase("DATETIME") || type.equalsIgnoreCase("TIMESTAMP") || type.toUpperCase().equals("DATE") || type.toUpperCase().equals("TIME")) { res.append("<" + objectField + " type=\"XMLGregorianCalendar\"><![CDATA[" + rec.getString(cname) + "]]></" + objectField + ">"); } else if (type.equalsIgnoreCase("LONG") || type.equalsIgnoreCase("TINY") || type.equalsIgnoreCase("BIT") || type.equalsIgnoreCase("BIGINT") || type.equalsIgnoreCase("SMALLINT") || type.equalsIgnoreCase("TINYINT") || type.equalsIgnoreCase("MEDIUMINT") || type.equalsIgnoreCase("INT")) { res.append("<" + objectField + " type=\"BigInteger\"><![CDATA[" + rec.getInt(cname) + "]]></" + objectField + ">"); } else if (type.equalsIgnoreCase("DOUBLE") || type.equalsIgnoreCase("NUMERIC") || type.equalsIgnoreCase("DECIMAL")) { res.append("<" + objectField + " type=\"Double\"><![CDATA[" + rec.getDouble(cname) + "]]></" + objectField + ">"); } else if (type.equalsIgnoreCase("FLOAT")) { res.append("<" + objectField + " type=\"Float\"><![CDATA[" + rec.getFloat(cname) + "]]></" + objectField + ">"); } /*else if (type.equalsIgnoreCase("LONG")) { res.append("<"+proper(cname)+" type=\"Long\"><![CDATA["+rec.getDouble(cname)+"]]></"+proper(cname)+">"); }*/ else { //res.append("<"+proper(objectField)+" type=\""+cname+"\"><![CDATA["+rec.getString(cname)+"]]></"+proper(objectField)+">"); throw new Exception(objectField + " type " + type + " is not recognized."); } } } res.append("</" + tablename + ">"); } //System.out.println(">>>1:"+res.toString()); return new String(res.substring(0).getBytes("UTF8")); }