List of usage examples for java.util.concurrent ConcurrentHashMap get
public V get(Object key)
From source file:ddf.catalog.source.opensearch.TestOpenSearchSource.java
private void verifyOpenSearchUrl(List<NameValuePair> pairs, NameValuePair... answers) { ConcurrentHashMap<String, String> nvpMap = createMapFor(pairs); for (NameValuePair answerPair : answers) { assertThat(nvpMap.get(answerPair.getName()), is(answerPair.getValue())); nvpMap.remove(answerPair.getName()); }/* w ww . j av a 2s . c om*/ assertThat(nvpMap.get("count"), is("20")); nvpMap.remove("count"); assertThat(nvpMap.get("mt"), is("0")); nvpMap.remove("mt"); assertThat(nvpMap.get("src"), is("local")); nvpMap.remove("src"); verifyAllEntriesBlank(nvpMap); }
From source file:org.wso2.carbon.event.input.adaptor.websocket.WebsocketEventAdaptorType.java
@Override public String subscribe(InputEventAdaptorMessageConfiguration inputEventAdaptorMessageConfiguration, InputEventAdaptorListener inputEventAdaptorListener, InputEventAdaptorConfiguration inputEventAdaptorConfiguration, AxisConfiguration axisConfiguration) { String subscriptionId = UUID.randomUUID().toString(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); String topic = inputEventAdaptorMessageConfiguration.getInputMessageProperties() .get(WebsocketEventAdaptorConstants.ADAPTOR_MESSAGE_TOPIC); String socketServerUrl = inputEventAdaptorConfiguration.getInputProperties() .get(WebsocketEventAdaptorConstants.ADAPTER_SERVER_URL); if (!socketServerUrl.startsWith("ws://")) { throw new InputEventAdaptorEventProcessingException( "Provided websocket URL " + socketServerUrl + " is invalid."); //TODO: Make this exception propagate to the UI. }/* w ww. j av a 2 s. c om*/ if (topic != null) { socketServerUrl = socketServerUrl + "/" + topic; } else { topic = ""; //Using empty string to map the cases with no topic, because topic is optional } ConcurrentHashMap<String, ConcurrentHashMap<String, CopyOnWriteArrayList<ClientManagerWrapper>>> tenantSpecificAdaptorMap = inputEventAdaptorClientManagerMap .get(tenantId); if (tenantSpecificAdaptorMap == null) { tenantSpecificAdaptorMap = new ConcurrentHashMap<String, ConcurrentHashMap<String, CopyOnWriteArrayList<ClientManagerWrapper>>>(); if (null != inputEventAdaptorClientManagerMap.putIfAbsent(tenantId, tenantSpecificAdaptorMap)) { tenantSpecificAdaptorMap = inputEventAdaptorClientManagerMap.get(tenantId); } } ConcurrentHashMap<String, CopyOnWriteArrayList<ClientManagerWrapper>> adaptorSpecificTopicMap = tenantSpecificAdaptorMap .get(inputEventAdaptorConfiguration.getName()); if (adaptorSpecificTopicMap == null) { adaptorSpecificTopicMap = new ConcurrentHashMap<String, CopyOnWriteArrayList<ClientManagerWrapper>>(); if (null != tenantSpecificAdaptorMap.put(inputEventAdaptorConfiguration.getName(), adaptorSpecificTopicMap)) { adaptorSpecificTopicMap = tenantSpecificAdaptorMap.get(inputEventAdaptorConfiguration.getName()); } } CopyOnWriteArrayList<ClientManagerWrapper> topicSpecificClientManagers = adaptorSpecificTopicMap.get(topic); if (topicSpecificClientManagers == null) { topicSpecificClientManagers = new CopyOnWriteArrayList<ClientManagerWrapper>(); if (null != adaptorSpecificTopicMap.putIfAbsent(topic, topicSpecificClientManagers)) { topicSpecificClientManagers = adaptorSpecificTopicMap.get(topic); } } ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().build(); ClientManager client = ClientManager.createClient(); ClientManagerWrapper clientManagerWrapper = new ClientManagerWrapper(); clientManagerWrapper.setClientManager(client); clientManagerWrapper.setSubscriptionId(subscriptionId); try { client.connectToServer(new WebsocketClient(inputEventAdaptorListener), clientEndpointConfig, new URI(socketServerUrl)); //TODO: Handle reconnecting, in case server disconnects. Suggestion: Create a scheduler. topicSpecificClientManagers.add(clientManagerWrapper); } catch (DeploymentException e) { throw new InputEventAdaptorEventProcessingException(e); //TODO: These exceptions might get modified into new types, as these do not propagate to the UI. } catch (IOException e) { throw new InputEventAdaptorEventProcessingException(e); } catch (Throwable e) { throw new InputEventAdaptorEventProcessingException(e); } return subscriptionId; }
From source file:com.alibaba.napoli.gecko.service.impl.BaseRemotingController.java
public Object getAttribute(final String url, final String key) { final ConcurrentHashMap<String, Object> subAttr = this.attributes.get(url); if (subAttr == null) { return null; }//from www. j a v a 2 s .c o m return subAttr.get(key); }
From source file:org.openhab.io.caldav.internal.CalDavLoaderImpl.java
private synchronized void addEventToMap(EventContainer eventContainer, boolean createTimer) { CalendarRuntime calendarRuntime = EventStorage.getInstance().getEventCache() .get(eventContainer.getCalendarId()); ConcurrentHashMap<String, EventContainer> eventContainerMap = calendarRuntime.getEventMap(); if (eventContainerMap.containsKey(eventContainer.getEventId())) { EventContainer eventContainerOld = eventContainerMap.get(eventContainer.getEventId()); // event is already in map if (eventContainer.getLastChanged().isAfter(eventContainerOld.getLastChanged())) { log.debug("event is already in event map and newer -> delete the old one, reschedule timer"); // cancel old jobs for (String timerKey : eventContainerOld.getTimerMap()) { try { this.scheduler.deleteJob(JobKey.jobKey(timerKey)); } catch (SchedulerException e) { log.error("cannot cancel event with job-id: " + timerKey, e); }/* w ww . j a v a 2 s .c o m*/ } eventContainerOld.getTimerMap().clear(); // override event eventContainerMap.put(eventContainer.getEventId(), eventContainer); for (EventNotifier notifier : eventListenerList) { for (CalDavEvent event : eventContainerOld.getEventList()) { log.trace("notify listener... {}", notifier); try { notifier.eventRemoved(event); } catch (Exception e) { log.error("error while invoking listener", e); } } } for (EventNotifier notifier : eventListenerList) { for (CalDavEvent event : eventContainer.getEventList()) { log.trace("notify listener... {}", notifier); try { notifier.eventLoaded(event); } catch (Exception e) { log.error("error while invoking listener", e); } } } if (createTimer) { int index = 0; for (CalDavEvent event : eventContainer.getEventList()) { if (event.getEnd().isAfterNow()) { try { createJob(eventContainer, event, index); } catch (SchedulerException e) { log.error("cannot create jobs for event: " + event.getShortName()); } } index++; } } } else { // event is already in map and not updated, ignoring } } else { // event is new eventContainerMap.put(eventContainer.getEventId(), eventContainer); log.trace("listeners for events: {}", eventListenerList.size()); for (EventNotifier notifier : eventListenerList) { for (CalDavEvent event : eventContainer.getEventList()) { log.trace("notify listener... {}", notifier); try { notifier.eventLoaded(event); } catch (Exception e) { log.error("error while invoking listener", e); } } } if (createTimer) { int index = 0; for (CalDavEvent event : eventContainer.getEventList()) { if (event.getEnd().isAfterNow()) { try { createJob(eventContainer, event, index); } catch (SchedulerException e) { log.error("cannot create jobs for event: " + event.getShortName()); } } index++; } } } }
From source file:org.apache.marmotta.ucuenca.wk.commons.function.SemanticDistance.java
/** * @param args the command line arguments *///from www.ja v a 2 s . com public synchronized double semanticKeywordsDistance(List<String> a, List<String> b) throws ClassNotFoundException, SQLException, IOException { Class.forName("org.postgresql.Driver"); conn = DriverManager.getConnection(dburl, user, pass); ConcurrentHashMap<String, List<String>> map = new ConcurrentHashMap<>(); List<String> authors = new ArrayList(); authors.add("a1"); authors.add("a2"); ConcurrentHashMap<String, Double> result = new ConcurrentHashMap<>(); double avg = 0; double har = 0; for (int i = 0; i < authors.size(); i++) { for (int j = i + 1; j < authors.size(); j++) { String a1 = authors.get(i); String a2 = authors.get(j); List<String> ka1 = null; List<String> ka2 = null; if (map.containsKey(a1)) { ka1 = map.get(a1); } else { ka1 = formatList(a);//consultado2R(a1, Endpoints.get(i)); map.put(a1, ka1); } if (map.containsKey(a2)) { ka2 = map.get(a2); } else { ka2 = formatList(b);//consultado2R(a2, Endpoints.get(j)); map.put(a2, ka2); } double sum = 0; double num = 0; for (String t1 : ka1) { for (String t2 : ka2) { num++; String tt1 = t1; String tt2 = t2; double v = ngd(tt1, tt2); sum += v; } } double prom = sum / num; if (num == 0 && sum == 0) { prom = 2; } result.put(i + "," + j, prom); avg = avg(avg, prom); har = har(har, prom); } } conn.close(); return mapEntry(result); }
From source file:org.atricore.idbus.kernel.main.databinding.JAXBUtils.java
/** * Create a JAXBContext using the contextPackages * * @param contextPackages Set<String> * @param cl ClassLoader//from w w w. j av a 2 s . c om * @param forceArrays boolean (true if JAXBContext must include all arrays) * @param properties Map of properties for the JAXBContext.newInstance creation method * @param classRefs List of class references * @return JAXBContextValue (JAXBContext + constructionType) * @throws javax.xml.bind.JAXBException */ private static JAXBContextValue createJAXBContextValue(TreeSet<String> contextPackages, ClassLoader cl, boolean forceArrays, Map<String, ?> properties, List<String> classRefs) throws JAXBException { JAXBContextValue contextValue = null; if (log.isDebugEnabled()) { log.debug("Following packages are in this batch of getJAXBContext() :"); for (String pkg : contextPackages) { log.debug(pkg); } log.debug("This classloader will be used to construct the JAXBContext" + cl); } // The contextPackages is a set of package names that are constructed using PackageSetBuilder. // PackageSetBuilder gets the packages names from various sources. // a) It walks the various annotations on the WebService collecting package names. // b) It walks the wsdl/schemas and builds package names for each target namespace. // // The combination of these two sources should produce all of the package names. // ------------- // Note that (b) is necessary for the following case: // An operation has a parameter named BASE. // Object DERIVED is an extension of BASE and is defined in a different package/schema. // In this case, there will not be any annotations on the WebService that reference DERIVED. // The only way to find the package for DERIVED is to walk the schemas. // ------------- Iterator<String> it = contextPackages.iterator(); while (it.hasNext()) { String p = it.next(); // Don't consider java and javax packages // REVIEW: We might have to refine this if (p.startsWith("javax.xml.ws.wsaddressing")) { continue; } if (p.startsWith("java.") || p.startsWith("javax.")) { it.remove(); } } // There are two ways to construct the context. // 1) USE A CONTEXTPATH, which is a string containing // all of the packages separated by colons. // 2) USE A CLASS[], which is an array of all of the classes // involved in the marshal/unmarshal. // // There are pros/cons with both approaches. // USE A CONTEXTPATH: // Pros: preferred way of doing this. // performant // most dynamic // Cons: Each package in context path must have an ObjectFactory // // // USE CLASS[]: // Pros: Doesn't require ObjectFactory in each package // Cons: Hard to set up, must account for JAX-WS classes, etc. // Does not work if arrays of classes are needed // slower // // The following code attempts to build a context path. It then // choose one of the two constructions above (prefer USE A CONTEXT_PATH) // // The packages are examined to see if they have ObjectFactory/package-info classes. // Invalid packages are removed from the list it = contextPackages.iterator(); boolean contextConstruction = (!forceArrays); boolean isJAXBFound = false; while (it.hasNext()) { String p = it.next(); // See if this package has an ObjectFactory or package-info if (checkPackage(p, cl)) { // Flow to here indicates package can be used for CONTEXT construction isJAXBFound = true; if (log.isDebugEnabled()) { log.debug("Package " + p + " contains an ObjectFactory or package-info class."); } } else { // Flow to here indicates that the package is not valid for context construction. // Perhaps the package is invalid. if (log.isDebugEnabled()) { log.debug("Package " + p + " does not contain an ObjectFactory or package-info class. Searching for JAXB classes"); } List<Class> classes = null; classes = getAllClassesFromPackage(p, cl); if (classes == null || classes.size() == 0) { if (log.isDebugEnabled()) { log.debug("Package " + p + " does not have any JAXB classes. It is removed from the JAXB context path."); } it.remove(); } else { // Classes are found in the package. We cannot use the CONTEXT construction contextConstruction = false; if (log.isDebugEnabled()) { log.debug("Package " + p + " does not contain ObjectFactory, but it does contain other JAXB classes."); } } } } if (!isJAXBFound) { if (log.isDebugEnabled()) { log.debug("ObjectFactory & package-info are not found in package hierachy"); } } // The code above may have removed some packages from the list. // Retry our lookup with the updated list if (contextConstruction) { if (log.isDebugEnabled()) { log.debug("Recheck Cache Start: Some packages have been removed from the list. Rechecking cache."); } String key = contextPackages.toString(); ConcurrentHashMap<ClassLoader, JAXBContextValue> innerMap = null; SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>> softRef = jaxbMap.get(key); if (softRef != null) { innerMap = softRef.get(); } if (innerMap != null) { contextValue = innerMap.get(cl); if (forceArrays && contextValue != null && contextValue.constructionType != JAXBUtils.CONSTRUCTION_TYPE.BY_CLASS_ARRAY_PLUS_ARRAYS) { if (log.isDebugEnabled()) { log.debug("Found a JAXBContextValue with constructionType=" + contextValue.constructionType + " but the caller requested a JAXBContext " + " that includes arrays. A new JAXBContext will be built"); } contextValue = null; } if (contextValue != null) { if (log.isDebugEnabled()) { log.debug("Successfully found JAXBContext with updated context list:" + contextValue.jaxbContext.toString()); } return contextValue; } } if (log.isDebugEnabled()) { log.debug("Recheck Cache End: Did not find a JAXBContext. Will build a new JAXBContext."); } } // CONTEXT construction if (contextConstruction) { if (log.isDebugEnabled()) { log.debug("Try building a JAXBContext using the packages only."); } JAXBContext context = createJAXBContextUsingContextPath(contextPackages, cl, classRefs); if (context != null) { contextValue = new JAXBContextValue(context, CONSTRUCTION_TYPE.BY_CONTEXT_PATH); } if (log.isDebugEnabled()) { log.debug("Building a JAXBContext with packages only success=" + (contextValue != null)); } } // CLASS construction if (contextValue == null) { if (log.isDebugEnabled()) { log.debug("Try building a JAXBContext using a list of classes."); log.debug("Start finding classes"); } it = contextPackages.iterator(); List<Class> fullList = new ArrayList<Class>(); while (it.hasNext()) { String pkg = it.next(); fullList.addAll(getAllClassesFromPackage(pkg, cl)); } //Lets add all common array classes addCommonArrayClasses(fullList); Class[] classArray = fullList.toArray(new Class[0]); if (log.isDebugEnabled()) { log.debug("End finding classes"); } JAXBContext context = JAXBContext_newInstance(classArray, cl, properties, classRefs); if (context != null) { if (forceArrays) { contextValue = new JAXBContextValue(context, CONSTRUCTION_TYPE.BY_CLASS_ARRAY_PLUS_ARRAYS); } else { contextValue = new JAXBContextValue(context, CONSTRUCTION_TYPE.BY_CLASS_ARRAY); } } } if (log.isDebugEnabled()) { log.debug("Successfully created JAXBContext " + contextValue.jaxbContext.toString()); } return contextValue; }
From source file:org.getobjects.ofs.OFSFolder.java
public OFSFileContainerChildInfo childInfo() { final IOFSFileInfo info = this.fileInfo(); if (info == null) return null; final long currentTimestamp = info.lastModified(); // need to rebuild caches? if (this.childInfo != null && currentTimestamp != this.lastModified) this.childInfo = null; if (this.childInfo == null) { final ConcurrentHashMap<IOFSFileInfo, Object> pathToChildInfo = this.fileManager .cacheForSection("OFSFolderChildInfo"); /* check cache */ this.childInfo = (OFSFileContainerChildInfo) pathToChildInfo.get(info); if (this.childInfo != null) { // Hm, this does not seem to speedup the operation, even though we get // a good hitrate? Maybe the kernel cache is sufficient or the File // does some caching? if (currentTimestamp != this.childInfo.timestamp()) { // no gain in removing the old info? Will be overridden below this.childInfo = null; }/*from w ww .j a v a 2 s . c o m*/ } /* fetch item if cache was empty or item got changed */ if (this.childInfo == null) { this.childInfo = OFSFileContainerChildInfo.infoForFile(this.fileManager(), this.fileInfo()); if (this.childInfo != null) { this.childInfo.load(); /* ensure a threadsafe state */ pathToChildInfo.put(info, this.childInfo); } } } return this.childInfo; }
From source file:com.athena.sqs.MessageAggregator.java
/** * Aggregate splitted messages into single message. * @param rawData base64 string//from www . j a v a 2 s .c o m * @throws MessageException */ public void aggregate(String rawString) throws MessageException { try { BASE64Decoder decoder = new BASE64Decoder(); int index = rawString.indexOf(MessageContext.DATA_DELIMITER); // 1. Split header String[] header = parseHeader(rawString.substring(0, index)); String content = rawString.substring(index + 2); // 2. Assign header value to local variable MessageTransferType transferType = MessageTransferType.valueOf(header[0]); String businessName = header[1]; String transactionId = header[2]; MessageSplitType splitType = MessageSplitType.valueOf(header[3]); int current = Integer.parseInt(header[4]); int total = Integer.parseInt(header[5]); // 3 Check Message Single switch (splitType) { case SINGLE: // TODO single message work doProcess(transactionId, new String(decoder.decodeBuffer(content))); return; case MULTI: break; } logger.debug("Transaction ID : " + transactionId); // 4. Check Message Order // If transaction id is not exist in txMap, create new tx map object if (!txMap.containsKey(transactionId)) { ConcurrentHashMap<Integer, String> orderedMessages = new ConcurrentHashMap<Integer, String>(); orderedMessages.put(current, content); txMap.put(transactionId, orderedMessages); } else { // Already same transaction message was inserted ConcurrentHashMap<Integer, String> orderedMessages = txMap.get(transactionId); orderedMessages.put(current, content); // Message compare if (orderedMessages.size() == total) { // All messages arrived Object[] key = orderedMessages.keySet().toArray(); Arrays.sort(key); String finalMessage = ""; for (int i = 0; i < key.length; i++) { finalMessage += orderedMessages.get(key[i]); } logger.debug("===== [ " + transactionId + "] ======"); logger.debug(new String(decoder.decodeBuffer(finalMessage))); boolean isDelete = txMap.remove(transactionId, orderedMessages); if (!isDelete) { throw new MessageException("Can't delete message from transaction map"); } doProcess(transactionId, new String(decoder.decodeBuffer(finalMessage))); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.apache.axis2.jaxws.message.databinding.JAXBUtils.java
/** * Create a JAXBContext using the contextPackages * * @param contextPackages Set<String> * @param cl ClassLoader/*from w ww . ja va2s.co m*/ * @param forceArrays boolean (true if JAXBContext must include all arrays) * @param properties Map of properties for the JAXBContext.newInstance creation method * @param classRefs List of class references * @return JAXBContextValue (JAXBContext + constructionType) * @throws JAXBException */ private static JAXBContextValue createJAXBContextValue(TreeSet<String> contextPackages, ClassLoader cl, boolean forceArrays, Map<String, ?> properties, List<String> classRefs) throws JAXBException { JAXBContextValue contextValue = null; if (log.isDebugEnabled()) { log.debug("Following packages are in this batch of getJAXBContext() :"); for (String pkg : contextPackages) { log.debug(pkg); } log.debug("This classloader will be used to construct the JAXBContext" + cl); } // The contextPackages is a set of package names that are constructed using PackageSetBuilder. // PackageSetBuilder gets the packages names from various sources. // a) It walks the various annotations on the WebService collecting package names. // b) It walks the wsdl/schemas and builds package names for each target namespace. // // The combination of these two sources should produce all of the package names. // ------------- // Note that (b) is necessary for the following case: // An operation has a parameter named BASE. // Object DERIVED is an extension of BASE and is defined in a different package/schema. // In this case, there will not be any annotations on the WebService that reference DERIVED. // The only way to find the package for DERIVED is to walk the schemas. // ------------- Iterator<String> it = contextPackages.iterator(); while (it.hasNext()) { String p = it.next(); // Don't consider java and javax packages // REVIEW: We might have to refine this if (p.startsWith("javax.xml.ws.wsaddressing")) { continue; } if (p.startsWith("java.") || p.startsWith("javax.")) { it.remove(); } } // There are two ways to construct the context. // 1) USE A CONTEXTPATH, which is a string containing // all of the packages separated by colons. // 2) USE A CLASS[], which is an array of all of the classes // involved in the marshal/unmarshal. // // There are pros/cons with both approaches. // USE A CONTEXTPATH: // Pros: preferred way of doing this. // performant // most dynamic // Cons: Each package in context path must have an ObjectFactory // // // USE CLASS[]: // Pros: Doesn't require ObjectFactory in each package // Cons: Hard to set up, must account for JAX-WS classes, etc. // Does not work if arrays of classes are needed // slower // // The following code attempts to build a context path. It then // choose one of the two constructions above (prefer USE A CONTEXT_PATH) // // The packages are examined to see if they have ObjectFactory/package-info classes. // Invalid packages are removed from the list it = contextPackages.iterator(); boolean contextConstruction = (!forceArrays); boolean isJAXBFound = false; while (it.hasNext()) { String p = it.next(); // See if this package has an ObjectFactory or package-info if (checkPackage(p, cl)) { // Flow to here indicates package can be used for CONTEXT construction isJAXBFound = true; if (log.isDebugEnabled()) { log.debug("Package " + p + " contains an ObjectFactory or package-info class."); } } else { // Flow to here indicates that the package is not valid for context construction. // Perhaps the package is invalid. if (log.isDebugEnabled()) { log.debug("Package " + p + " does not contain an ObjectFactory or package-info class. Searching for JAXB classes"); } List<Class> classes = null; classes = getAllClassesFromPackage(p, cl); if (classes == null || classes.size() == 0) { if (log.isDebugEnabled()) { log.debug("Package " + p + " does not have any JAXB classes. It is removed from the JAXB context path."); } it.remove(); } else { // Classes are found in the package. We cannot use the CONTEXT construction contextConstruction = false; if (log.isDebugEnabled()) { log.debug("Package " + p + " does not contain ObjectFactory, but it does contain other JAXB classes."); } } } } if (!isJAXBFound) { if (log.isDebugEnabled()) { log.debug("ObjectFactory & package-info are not found in package hierachy"); } } // The code above may have removed some packages from the list. // Retry our lookup with the updated list if (contextConstruction) { if (log.isDebugEnabled()) { log.debug("Recheck Cache Start: Some packages have been removed from the list. Rechecking cache."); } String key = contextPackages.toString(); ConcurrentHashMap<ClassLoader, JAXBContextValue> innerMap = null; SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>> softRef = jaxbMap.get(key); if (softRef != null) { innerMap = softRef.get(); } if (innerMap != null) { contextValue = innerMap.get(cl); if (forceArrays && contextValue != null && contextValue.constructionType != JAXBUtils.CONSTRUCTION_TYPE.BY_CLASS_ARRAY_PLUS_ARRAYS) { if (log.isDebugEnabled()) { log.debug("Found a JAXBContextValue with constructionType=" + contextValue.constructionType + " but the caller requested a JAXBContext " + " that includes arrays. A new JAXBContext will be built"); } contextValue = null; } if (contextValue != null) { if (log.isDebugEnabled()) { log.debug("Successfully found JAXBContext with updated context list:" + contextValue.jaxbContext.toString()); } return contextValue; } } if (log.isDebugEnabled()) { log.debug("Recheck Cache End: Did not find a JAXBContext. Will build a new JAXBContext."); } } // CONTEXT construction if (contextConstruction) { if (log.isDebugEnabled()) { log.debug("Try building a JAXBContext using the packages only."); } JAXBContext context = createJAXBContextUsingContextPath(contextPackages, cl, classRefs); if (context != null) { contextValue = new JAXBContextValue(context, CONSTRUCTION_TYPE.BY_CONTEXT_PATH); } if (log.isDebugEnabled()) { log.debug("Building a JAXBContext with packages only success=" + (contextValue != null)); } } // CLASS construction if (contextValue == null) { if (log.isDebugEnabled()) { log.debug("Try building a JAXBContext using a list of classes."); log.debug("Start finding classes"); } it = contextPackages.iterator(); List<Class> fullList = new ArrayList<Class>(); while (it.hasNext()) { String pkg = it.next(); fullList.addAll(getAllClassesFromPackage(pkg, cl)); } //Lets add all common array classes addCommonArrayClasses(fullList); Class[] classArray = fullList.toArray(new Class[0]); if (log.isDebugEnabled()) { log.debug("End finding classes"); } JAXBContext context = JAXBContext_newInstance(classArray, cl, properties, classRefs); if (context != null) { if (forceArrays) { contextValue = new JAXBContextValue(context, CONSTRUCTION_TYPE.BY_CLASS_ARRAY_PLUS_ARRAYS); } else { contextValue = new JAXBContextValue(context, CONSTRUCTION_TYPE.BY_CLASS_ARRAY); } } } if (log.isDebugEnabled()) { log.debug("Successfully created JAXBContext " + contextValue.jaxbContext.toString()); } return contextValue; }
From source file:org.wso2.carbon.event.input.adaptor.file.FileEventAdaptorType.java
private void createFileAdaptorListener( InputEventAdaptorMessageConfiguration inputEventAdaptorMessageConfiguration, InputEventAdaptorListener inputEventAdaptorListener, InputEventAdaptorConfiguration inputEventAdaptorConfiguration, AxisConfiguration axisConfiguration, String subscriptionId) {// w w w . j ava2s .com log.info("New subscriber added for " + inputEventAdaptorConfiguration.getName()); ConcurrentHashMap<String, FileTailerManager> tailerManagerConcurrentHashMap = tailerMap .get(inputEventAdaptorConfiguration.getName()); if (tailerManagerConcurrentHashMap == null) { tailerManagerConcurrentHashMap = new ConcurrentHashMap<String, FileTailerManager>(); if (null != tailerMap.putIfAbsent(inputEventAdaptorConfiguration.getName(), tailerManagerConcurrentHashMap)) { tailerManagerConcurrentHashMap = tailerMap.get(inputEventAdaptorConfiguration.getName()); } } String filepath = inputEventAdaptorMessageConfiguration.getInputMessageProperties() .get(FileEventAdaptorConstants.EVENT_ADAPTOR_CONF_FILEPATH); FileTailerManager fileTailerManager = tailerManagerConcurrentHashMap.get(filepath); if (fileTailerManager == null) { FileTailerListener listener = new FileTailerListener(new File(filepath).getName()); Tailer tailer = new Tailer(new File(filepath), listener); fileTailerManager = new FileTailerManager(tailer, listener); listener.addListener(subscriptionId, inputEventAdaptorListener); tailerManagerConcurrentHashMap.put(filepath, fileTailerManager); threadPoolExecutor.execute(tailer); } else { fileTailerManager.getListener().addListener(subscriptionId, inputEventAdaptorListener); } }