List of usage examples for java.util.concurrent CopyOnWriteArrayList add
public boolean add(E e)
From source file:com.web.server.util.ClassLoaderUtil.java
public static CopyOnWriteArrayList closeClassLoader(ClassLoader cl) { CopyOnWriteArrayList jars = new CopyOnWriteArrayList(); boolean res = false; Class classURLClassLoader = null; if (cl instanceof URLClassLoader) classURLClassLoader = URLClassLoader.class; else if (cl instanceof VFSClassLoader) { classURLClassLoader = VFSClassLoader.class; }/*from w ww . j ava 2s .c o m*/ Field f = null; try { f = classURLClassLoader.getDeclaredField("ucp"); System.out.println(f); } catch (NoSuchFieldException e1) { // e1.printStackTrace(); // log.info(e1.getMessage(), e1); } if (f != null) { f.setAccessible(true); Object obj = null; try { obj = f.get(cl); } catch (IllegalAccessException e1) { // e1.printStackTrace(); // log.info(e1.getMessage(), e1); } if (obj != null) { final Object ucp = obj; f = null; try { f = ucp.getClass().getDeclaredField("loaders"); System.out.println(f); } catch (NoSuchFieldException e1) { // e1.printStackTrace(); // log.info(e1.getMessage(), e1); } if (f != null) { f.setAccessible(true); ArrayList loaders = null; try { loaders = (ArrayList) f.get(ucp); res = true; } catch (IllegalAccessException e1) { // e1.printStackTrace(); } for (int i = 0; loaders != null && i < loaders.size(); i++) { obj = loaders.get(i); f = null; try { f = obj.getClass().getDeclaredField("jar"); // log.info(f); } catch (NoSuchFieldException e) { // e.printStackTrace(); // log.info(e.getMessage(), e); } if (f != null) { f.setAccessible(true); try { obj = f.get(obj); } catch (IllegalAccessException e1) { // e1.printStackTrace(); // log.info(e1.getMessage(), e1); } if (obj instanceof JarFile) { final JarFile jarFile = (JarFile) obj; System.out.println(jarFile.getName()); jars.add(jarFile.getName().replace("/", "\\").trim().toUpperCase()); // try { // jarFile.getManifest().clear(); // } catch (IOException e) { // // ignore // } try { jarFile.close(); } catch (IOException e) { e.printStackTrace(); // ignore // log.info(e.getMessage(), e); } } } } } } } return jars; }
From source file:com.microsoft.windowsazure.mobileservices.notifications.MobileServicePush.java
private ListenableFuture<Void> unregisterAllInternal(ArrayList<Registration> registrations) { final SettableFuture<Void> resultFuture = SettableFuture.create(); final SyncState state = new SyncState(); state.size = registrations.size();// w w w .j a va 2 s.c o m final CopyOnWriteArrayList<String> concurrentArray = new CopyOnWriteArrayList<String>(); final Object syncObject = new Object(); if (state.size == 0) { removeAllRegistrationsId(); mIsRefreshNeeded = false; resultFuture.set(null); return resultFuture; } for (final Registration registration : registrations) { ListenableFuture<Void> serviceFilterFuture = deleteRegistrationInternal(registration.getName(), registration.getRegistrationId()); Futures.addCallback(serviceFilterFuture, new FutureCallback<Void>() { @Override public void onFailure(Throwable exception) { if (exception != null) { synchronized (syncObject) { if (!state.alreadyReturn) { state.alreadyReturn = true; resultFuture.setException(exception); return; } } } } @Override public void onSuccess(Void v) { concurrentArray.add(registration.getRegistrationId()); if (concurrentArray.size() == state.size && !state.alreadyReturn) { removeAllRegistrationsId(); mIsRefreshNeeded = false; resultFuture.set(null); return; } } }); } return resultFuture; }
From source file:io.druid.indexing.kafka.supervisor.KafkaSupervisor.java
private void addDiscoveredTaskToPendingCompletionTaskGroups(int groupId, String taskId, Map<Integer, Long> startingPartitions) { pendingCompletionTaskGroups.putIfAbsent(groupId, Lists.<TaskGroup>newCopyOnWriteArrayList()); CopyOnWriteArrayList<TaskGroup> taskGroupList = pendingCompletionTaskGroups.get(groupId); for (TaskGroup taskGroup : taskGroupList) { if (taskGroup.partitionOffsets.equals(startingPartitions)) { if (taskGroup.tasks.putIfAbsent(taskId, new TaskData()) == null) { log.info("Added discovered task [%s] to existing pending task group", taskId); }//from www.ja v a 2s. co m return; } } log.info("Creating new pending completion task group for discovered task [%s]", taskId); // reading the minimumMessageTime from the publishing task and setting it here is not necessary as this task cannot // change to a state where it will read any more events TaskGroup newTaskGroup = new TaskGroup(ImmutableMap.copyOf(startingPartitions), Optional.<DateTime>absent()); newTaskGroup.tasks.put(taskId, new TaskData()); newTaskGroup.completionTimeout = DateTime.now().plus(ioConfig.getCompletionTimeout()); taskGroupList.add(newTaskGroup); }
From source file:com.app.server.SARDeployer.java
/** * This method extracts the SAR archive and configures for the SAR and starts the services * @param file/* w ww .j a v a 2 s . co m*/ * @param warDirectoryPath * @throws IOException */ public void extractSarDeploy(ClassLoader cL, Object... args) throws IOException { CopyOnWriteArrayList classPath = null; File file = null; String fileName = ""; String fileWithPath = ""; if (args[0] instanceof File) { classPath = new CopyOnWriteArrayList(); file = (File) args[0]; fileWithPath = file.getAbsolutePath(); ZipFile zip = new ZipFile(file); ZipEntry ze = null; fileName = file.getName(); fileName = fileName.substring(0, fileName.indexOf('.')); fileName += "sar"; String fileDirectory; Enumeration<? extends ZipEntry> entries = zip.entries(); int numBytes; while (entries.hasMoreElements()) { ze = entries.nextElement(); // //log.info("Unzipping " + ze.getName()); String filePath = serverConfig.getDeploydirectory() + "/" + fileName + "/" + 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(".jar")) { classPath.add(filePath); } } } zip.close(); } else if (args[0] instanceof FileObject) { FileObject fileObj = (FileObject) args[0]; fileName = fileObj.getName().getBaseName(); try { fileWithPath = fileObj.getURL().toURI().toString(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } fileName = fileName.substring(0, fileName.indexOf('.')); fileName += "sar"; classPath = unpack(fileObj, new File(serverConfig.getDeploydirectory() + "/" + fileName + "/"), (StandardFileSystemManager) args[1]); } URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader(); URL[] urls = loader.getURLs(); WebClassLoader sarClassLoader; if (cL != null) { sarClassLoader = new WebClassLoader(urls, cL); } else { sarClassLoader = new WebClassLoader(urls); } for (int index = 0; index < classPath.size(); index++) { // log.info("file:"+classPath.get(index)); sarClassLoader.addURL(new URL("file:" + classPath.get(index))); } sarClassLoader.addURL(new URL("file:" + serverConfig.getDeploydirectory() + "/" + fileName + "/")); //log.info(sarClassLoader.geturlS()); sarsMap.put(fileWithPath, sarClassLoader); try { Sar sar = (Sar) sardigester.parse(new InputSource(new FileInputStream( serverConfig.getDeploydirectory() + "/" + fileName + "/META-INF/" + "mbean-service.xml"))); CopyOnWriteArrayList mbeans = sar.getMbean(); //log.info(mbeanServer); ObjectName objName, classLoaderObjectName = new ObjectName("com.app.server:classLoader=" + fileName); if (!mbeanServer.isRegistered(classLoaderObjectName)) { mbeanServer.registerMBean(sarClassLoader, classLoaderObjectName); } else { mbeanServer.unregisterMBean(classLoaderObjectName); mbeanServer.registerMBean(sarClassLoader, classLoaderObjectName); ; } for (int index = 0; index < mbeans.size(); index++) { Mbean mbean = (Mbean) mbeans.get(index); //log.info(mbean.getObjectname()); //log.info(mbean.getCls()); objName = new ObjectName(mbean.getObjectname()); Class service = sarClassLoader.loadClass(mbean.getCls()); if (mbeanServer.isRegistered(objName)) { //mbs.invoke(objName, "stopService", null, null); //mbs.invoke(objName, "destroy", null, null); mbeanServer.unregisterMBean(objName); } mbeanServer.createMBean(service.getName(), objName, classLoaderObjectName); //mbs.registerMBean(obj, objName); CopyOnWriteArrayList attrlist = mbean.getMbeanAttribute(); if (attrlist != null) { for (int count = 0; count < attrlist.size(); count++) { MBeanAttribute attr = (MBeanAttribute) attrlist.get(count); Attribute mbeanattribute = new Attribute(attr.getName(), attr.getValue()); mbeanServer.setAttribute(objName, mbeanattribute); } } Attribute mbeanattribute = new Attribute("ObjectName", objName); mbeanServer.setAttribute(objName, mbeanattribute); if (((String) mbeanServer.getAttribute(objName, "Deployer")).equals("true")) { mbeanServer.invoke(objName, "init", new Object[] { deployerList }, new String[] { Vector.class.getName() }); } mbeanServer.invoke(objName, "init", new Object[] { serviceList, serverConfig, mbeanServer }, new String[] { Vector.class.getName(), ServerConfig.class.getName(), MBeanServer.class.getName() }); mbeanServer.invoke(objName, "start", null, null); serviceListObjName.put(fileWithPath, objName); } } catch (Exception e) { log.error("Could not able to deploy sar archive " + fileWithPath, e); // TODO Auto-generated catch block //e.printStackTrace(); } }
From source file:io.druid.indexing.jdbc.supervisor.JDBCSupervisor.java
private void addDiscoveredTaskToPendingCompletionTaskGroups(int groupId, String taskId, Map<Integer, Long> offsetMaps) { pendingCompletionTaskGroups.putIfAbsent(groupId, Lists.<TaskGroup>newCopyOnWriteArrayList()); CopyOnWriteArrayList<TaskGroup> taskGroupList = pendingCompletionTaskGroups.get(groupId); for (TaskGroup taskGroup : taskGroupList) { log.info("TaskGroup Offset Info [%s] vs offsetMaps [%s]", taskGroup.offsetsMap, offsetMaps); if (taskGroup.offsetsMap.equals(offsetMaps)) { if (taskGroup.tasks.putIfAbsent(taskId, new TaskData()) == null) { log.info("Added discovered task [%s] to existing pending task group", taskId); }/* w ww .jav a2s . co m*/ return; } } log.info("Creating new pending completion task group for discovered task [%s]", taskId); // reading the minimumMessageTime from the publishing task and setting it here is not necessary as this task cannot // change to a state where it will read any more events TaskGroup newTaskGroup = new TaskGroup(ImmutableMap.copyOf(offsetMaps), Optional.<DateTime>absent()); newTaskGroup.tasks.put(taskId, new TaskData()); newTaskGroup.completionTimeout = DateTime.now().plus(ioConfig.getCompletionTimeout()); taskGroupList.add(newTaskGroup); }
From source file:com.l2jfree.gameserver.model.entity.events.CTF.java
public static void CheckRestoreFlags() { CopyOnWriteArrayList<Integer> teamsTakenFlag = new CopyOnWriteArrayList<Integer>(); try {//from w w w . j a v a2 s. c om for (L2Player player : _players) { //if there's a player with a flag //add the index of the team who's FLAG WAS TAKEN to the list if (player != null) { final CTFPlayerInfo info = player.as(CTFPlayerInfo.class); if (player.isOnline() == 0 && info._haveFlagCTF)// logged off with a flag in his hands { AnnounceToPlayers(false, _eventName + "(CTF): " + player.getName() + " logged off with a CTF flag!"); info._haveFlagCTF = false; if (_teams.indexOf(info._teamNameHaveFlagCTF) >= 0) { if (_flagsTaken.get(_teams.indexOf(info._teamNameHaveFlagCTF))) { _flagsTaken.set(_teams.indexOf(info._teamNameHaveFlagCTF), false); spawnFlag(info._teamNameHaveFlagCTF); AnnounceToPlayers(false, _eventName + "(CTF): " + info._teamNameHaveFlagCTF + " flag now returned to place."); } } removeFlagFromPlayer(player); info._teamNameHaveFlagCTF = null; return; } else if (info._haveFlagCTF) teamsTakenFlag.add(_teams.indexOf(info._teamNameHaveFlagCTF)); } } //Go over the list of ALL teams for (String team : _teams) { if (team == null) continue; int index = _teams.indexOf(team); if (!teamsTakenFlag.contains(index)) { if (_flagsTaken.get(index)) { _flagsTaken.set(index, false); spawnFlag(team); AnnounceToPlayers(false, _eventName + "(CTF): " + team + " flag returned due to player error."); } } } //Check if a player ran away from the event holding a flag: for (L2Player player : _players) { if (player == null) continue; final CTFPlayerInfo info = player.as(CTFPlayerInfo.class); if (info._haveFlagCTF) { if (isOutsideCTFArea(player)) { AnnounceToPlayers(false, _eventName + "(CTF): " + player.getName() + " escaped from the event holding a flag!"); info._haveFlagCTF = false; if (_teams.indexOf(info._teamNameHaveFlagCTF) >= 0) { if (_flagsTaken.get(_teams.indexOf(info._teamNameHaveFlagCTF))) { _flagsTaken.set(_teams.indexOf(info._teamNameHaveFlagCTF), false); spawnFlag(info._teamNameHaveFlagCTF); AnnounceToPlayers(false, _eventName + "(CTF): " + info._teamNameHaveFlagCTF + " flag now returned to place."); } } removeFlagFromPlayer(player); info._teamNameHaveFlagCTF = null; player.teleToLocation(_teamsX.get(_teams.indexOf(info._teamNameCTF)), _teamsY.get(_teams.indexOf(info._teamNameCTF)), _teamsZ.get(_teams.indexOf(info._teamNameCTF))); player.sendMessage("You have been returned to your team spawn"); return; } } } } catch (Exception e) { _log.info("CTF.restoreFlags() Error:", e); } }
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); }/*from w w w. j av a 2 s . c om*/ // 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.apache.druid.indexing.kafka.supervisor.KafkaSupervisor.java
private void addDiscoveredTaskToPendingCompletionTaskGroups(int groupId, String taskId, Map<Integer, Long> startingPartitions) { final CopyOnWriteArrayList<TaskGroup> taskGroupList = pendingCompletionTaskGroups.computeIfAbsent(groupId, k -> new CopyOnWriteArrayList<>()); for (TaskGroup taskGroup : taskGroupList) { if (taskGroup.partitionOffsets.equals(startingPartitions)) { if (taskGroup.tasks.putIfAbsent(taskId, new TaskData()) == null) { log.info("Added discovered task [%s] to existing pending task group [%s]", taskId, groupId); }/*from w w w. j a va2s. com*/ return; } } log.info("Creating new pending completion task group [%s] for discovered task [%s]", groupId, taskId); // reading the minimumMessageTime & maximumMessageTime from the publishing task and setting it here is not necessary as this task cannot // change to a state where it will read any more events TaskGroup newTaskGroup = new TaskGroup(groupId, ImmutableMap.copyOf(startingPartitions), Optional.absent(), Optional.absent()); newTaskGroup.tasks.put(taskId, new TaskData()); newTaskGroup.completionTimeout = DateTimes.nowUtc().plus(ioConfig.getCompletionTimeout()); taskGroupList.add(newTaskGroup); }
From source file:com.app.server.EARDeployer.java
public void obtainUrls(FileObject rootEar, FileObject ear, CopyOnWriteArrayList<URL> fileObjects, CopyOnWriteArrayList<FileObject> warObjects, CopyOnWriteArrayList<FileObject> jarObjects, CopyOnWriteArrayList<FileObject> sarObjects, CopyOnWriteArrayList<FileObject> rarObjects, CopyOnWriteArrayList<FileObject> ezbObjects, 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, warObjects, jarObjects, sarObjects, rarObjects, ezbObjects, fsManager); }/*from w ww .j a v a 2 s. c o m*/ // log.info(childrenJars[childcount]); // log.info(childrenJars[childcount].getName().getBaseName()); // log.info(ear.getURL()); if (childrenJars[childcount].getType() == FileType.FILE && (childrenJars[childcount].getName().getBaseName().endsWith(".jar") || childrenJars[childcount].getName().getBaseName().endsWith(".war") || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".rar") || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".sar"))) { // log.info(childrenJars[childcount].getURL()); if ((childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".war") || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".jar") || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".rar") || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".sar") || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".ezb")) && !childrenJars[childcount].getURL().toString().trim() .startsWith(rootEar.getURL().toString() + "lib/")) { //File file=new File(serverConfig.getDeploydirectory()+"/"+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(serverConfig.getDeploydirectory()+"/"+childrenJars[childcount].getName().getBaseName()+".part"); int len=0; while((len=fistr.read(filyByt))!=-1){ warFile.write(filyByt,0,len); } warFile.close(); fistr.close(); new File(serverConfig.getDeploydirectory()+"/"+childrenJars[childcount].getName().getBaseName()+".part").renameTo(file); warObjects.add(childrenJars[childcount]); }*/ if (childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".war")) { warObjects.add(childrenJars[childcount]); } else if (childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".jar")) { jarObjects.add(childrenJars[childcount]); } else if (childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".sar")) { sarObjects.add(childrenJars[childcount]); } else if (childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".rar")) { rarObjects.add(childrenJars[childcount]); } else if (childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".ezb")) { ezbObjects.add(childrenJars[childcount]); } } else { log.info("ear libs/" + childrenJars[childcount]); fileObjects.add(new URL(childrenJars[childcount].getURL().toString() .replace(rootEar.getURL().toString(), "rsrc:"))); } // log.info(childrenJars[childcount].getURL().toString()+" "+rootEar.getURL()); } else { childrenJars[childcount].close(); } } }