List of usage examples for java.util Collections synchronizedList
public static <T> List<T> synchronizedList(List<T> list)
From source file:blusunrize.immersiveengineering.client.models.ModelConveyor.java
@Override public List<BakedQuad> getQuads(@Nullable IBlockState blockState, @Nullable EnumFacing side, long rand) { TileEntity tile = null;//from www .ja v a 2s.c o m String key = "default"; EnumFacing facing = EnumFacing.NORTH; IConveyorBelt conveyor = defaultBelt; if (blockState == null) key = conveyor != null ? ConveyorHandler.reverseClassRegistry.get(conveyor.getClass()).toString() : "immersiveengineering:conveyor"; else { facing = blockState.getValue(IEProperties.FACING_ALL); if (blockState instanceof IExtendedBlockState) { IExtendedBlockState exState = (IExtendedBlockState) blockState; if (exState.getUnlistedNames().contains(BlockConveyor.ICONEYOR_PASSTHROUGH)) conveyor = ((IExtendedBlockState) blockState).getValue(BlockConveyor.ICONEYOR_PASSTHROUGH); if (exState.getUnlistedNames().contains(IEProperties.TILEENTITY_PASSTHROUGH)) tile = ((IExtendedBlockState) blockState).getValue(IEProperties.TILEENTITY_PASSTHROUGH); if (conveyor != null && tile != null) key = conveyor.getModelCacheKey(tile, facing); } } List<BakedQuad> cachedQuads = modelCache.get(key); if (cachedQuads != null) return ImmutableList.copyOf(cachedQuads); else { if (conveyor == null) conveyor = ConveyorHandler.getConveyor(new ResourceLocation(key), tile); cachedQuads = Collections.synchronizedList(Lists.newArrayList()); Matrix4f facingMatrix = TRSRTransformation.getMatrix(facing); if (conveyor != null) facingMatrix = conveyor.modifyBaseRotationMatrix(facingMatrix, tile, facing); Matrix4 matrix = new Matrix4(facingMatrix); ConveyorDirection conDir = conveyor != null ? conveyor.getConveyorDirection() : ConveyorDirection.HORIZONTAL; boolean[] walls = conveyor != null && tile != null ? new boolean[] { conveyor.renderWall(tile, facing, 0), conveyor.renderWall(tile, facing, 1) } : new boolean[] { true, true }; TextureAtlasSprite tex_conveyor = ClientUtils.mc().getTextureMapBlocks().getMissingSprite(); TextureAtlasSprite tex_conveyor_colour = null; int colourStripes = -1; if (conveyor != null) { tex_conveyor = ClientUtils.getSprite(tile != null ? (conveyor.isActive(tile) ? conveyor.getActiveTexture() : conveyor.getInactiveTexture()) : conveyor.getActiveTexture()); if ((colourStripes = conveyor.getDyeColour()) >= 0) tex_conveyor_colour = ClientUtils.getSprite(conveyor.getColouredStripesTexture()); } cachedQuads.addAll(getBaseConveyor(facing, 1, matrix, conDir, tex_conveyor, walls, new boolean[] { true, true }, tex_conveyor_colour, colourStripes)); if (conveyor != null) cachedQuads = conveyor.modifyQuads(cachedQuads, tile, facing); modelCache.put(key, ImmutableList.copyOf(cachedQuads)); return ImmutableList.copyOf(cachedQuads); } }
From source file:org.apache.syncope.core.persistence.dao.impl.SubjectSearchDAOImpl.java
@Override public int count(final Set<Long> adminRoles, final SearchCond searchCondition, final SubjectType type) { List<Object> parameters = Collections.synchronizedList(new ArrayList<Object>()); // 1. get the query string from the search condition SearchSupport svs = new SearchSupport(type); StringBuilder queryString = getQuery(searchCondition, parameters, type, svs); // 2. take into account administrative roles queryString.insert(0, "SELECT u.subject_id FROM ("); queryString.append(") u WHERE subject_id NOT IN ("); queryString.append(getAdminRolesFilter(adminRoles, type)).append(')'); // 3. prepare the COUNT query queryString.insert(0, "SELECT COUNT(subject_id) FROM ("); queryString.append(") count_subject_id"); Query countQuery = entityManager.createNativeQuery(queryString.toString()); fillWithParameters(countQuery, parameters); LOG.debug("Native count query\n{}\nwith parameters\n{}", queryString.toString(), parameters); int result = ((Number) countQuery.getSingleResult()).intValue(); LOG.debug("Native count query result: {}", result); return result; }
From source file:org.hupo.psi.mi.psicquic.registry.PsicquicRegistryServiceImpl.java
private Registry createRegistry(final ServiceFilter... filters) { Registry registry = new Registry(); final List<ServiceType> acceptedServices = Collections.synchronizedList(new ArrayList<ServiceType>(16)); for (final ServiceType service : config.getRegisteredServices()) { boolean accept = true; for (ServiceFilter filter : filters) { if (!filter.accept(service)) { accept = false;/*from w w w . ja v a 2s . c o m*/ } } if (accept) { acceptedServices.add(service); } } registry.getServices().addAll(acceptedServices); return registry; }
From source file:org.jboss.dashboard.commons.events.Publisher.java
/** * Retrieve registered Subscribers for a specified event. *//*from www . j a va2 s . c o m*/ public synchronized List getSubscribers(int eventId) { List results = Collections.synchronizedList(new ArrayList()); List eventSubscribers = (List) subscribers.get(new Integer(eventId)); if (eventSubscribers == null) return results; Iterator it = eventSubscribers.iterator(); while (it.hasNext()) { WeakReference wr = (WeakReference) it.next(); Subscriber subscriber = (Subscriber) wr.get(); if (subscriber == null) it.remove(); else results.add(subscriber); } return Collections.unmodifiableList(results); }
From source file:com.moss.posixfifosockets.testharness.TestHarness.java
public List<TestClient> run(TempDir temp, final int numClients, TestClientFactory factory) throws Exception { serverActivity = Collections.synchronizedList(new LinkedList<ServerActivity>()); final PosixFifoSocketAddress address = new PosixFifoSocketAddress(temp); PosixFifoSocketHandler handler = new PosixFifoSocketHandler() { public void handle(PosixFifoSocket socket) { ServerActivity a = new ServerActivity(socket); // serverActivity.add(a); try { a.handle();// w w w . jav a 2s .c o m } finally { // serverActivity.remove(a); } } }; server = new PosixFifoSocketServer(address, handler); server.start(); final List<TestClient> clients = new LinkedList<TestClient>(); final long start = System.currentTimeMillis(); for (int x = 0; x < numClients; x++) { final TestClient next = factory.newClient("Client " + x, address); clients.add(next); next.start(); } Thread monitor = new Thread("Reporting Thread") { public void run() { int lastTodo = 0; long lastChange = System.currentTimeMillis(); while (true) { int totalMax = 0; int totalTodo = 0; boolean allClientsDone = true; List<TestClient> activeClients = new LinkedList<TestClient>(); for (TestClient next : clients) { totalMax += next.MAX; totalTodo += next.y; if (next.isAlive()) { allClientsDone = false; activeClients.add(next); } } if (lastTodo != totalTodo) { lastTodo = totalTodo; lastChange = System.currentTimeMillis(); } System.out.println("Finished " + totalTodo + " of " + totalMax); double elapsed = (double) (System.currentTimeMillis() - start); double rate = ((double) totalTodo) / (elapsed / 1000.0); System.out.println(String.format(" Calls/Sec: %10.4f", rate)); if (System.currentTimeMillis() - lastChange > 5000) { SocketServerDebugHistory debug = server.debugInfo(); System.out.println("Progress seems to have halted."); System.out.println("Server: " + server.controlStatus()); System.out.println("Server has " + debug.activeHandlers().size() + " activte handlers"); for (Object next : debug.activeHandlers()) { System.out.println("Handler: " + next); } {// recent server activity // int x = server.getRecentHandlers().size()-10; // if(x<0) x=0; int x = 0; for (; x < server.debugInfo().inactiveHandlers().size(); x++) { System.out.println(" OLD HANDLER " + server.debugInfo().inactiveHandlers().get(x)); } } for (int x = 0; x < serverActivity.size(); x++) { ServerActivity next = serverActivity.get(x); System.out.println("Activity: " + next.toString()); } for (TestClient next : activeClients) { ServerActivity activity = null; for (int x = 0; x < serverActivity.size(); x++) { ServerActivity a = serverActivity.get(x); if (a.socket.id() == next.getId()) { activity = a; } } System.out.println(next.report() + " has completed " + next.y + " of " + next.MAX); System.out.println(" Server activity: " + activity); } System.exit(-1); } else { System.out.println(activeClients.size() + " active clients"); } try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } if (allClientsDone) { break; } } } }; monitor.start(); monitor.join(); return clients; }
From source file:com.adobe.acs.commons.mcp.impl.processes.cfi.ContentFragmentImport.java
private synchronized EnumMap<ReportColumns, Object> trackActivity(String item, String action, String description) {/*ww w . j a v a 2 s .com*/ if (reportRows == null) { reportRows = Collections.synchronizedList(new ArrayList<>()); } EnumMap<ReportColumns, Object> reportRow = new EnumMap<>(ReportColumns.class); reportRow.put(ReportColumns.ITEM, item); reportRow.put(ReportColumns.ACTION, action); reportRow.put(ReportColumns.DESCRIPTION, description); reportRow.put(ReportColumns.COUNT, 0L); reportRows.add(reportRow); return reportRow; }
From source file:org.alfresco.mobile.android.application.fragments.node.browser.NodeAdapter.java
public NodeAdapter(FragmentActivity activity, int textViewResourceId, List<Node> listItems, List<Node> selectedItems, int mode) { super(activity, textViewResourceId, listItems); originalNodes = Collections.synchronizedList(listItems); this.selectedItems = selectedItems; this.renditionManager = RenditionManagerImpl.getInstance(activity); this.mode = mode; this.vhClassName = TwoLinesProgressViewHolder.class.getCanonicalName(); this.activityRef = new WeakReference<>(activity); this.fromFavorites = true; }
From source file:org.apache.syncope.core.persistence.jpa.dao.JPASubjectSearchDAO.java
@Override public int count(final Set<Long> adminRoles, final SearchCond searchCondition, final SubjectType type) { List<Object> parameters = Collections.synchronizedList(new ArrayList<>()); // 1. get the query string from the search condition SearchSupport svs = new SearchSupport(type); StringBuilder queryString = getQuery(searchCondition, parameters, type, svs); // 2. take into account administrative roles queryString.insert(0, "SELECT u.subject_id FROM ("); queryString.append(") u WHERE subject_id NOT IN ("); queryString.append(getAdminRolesFilter(adminRoles, type)).append(')'); // 3. prepare the COUNT query queryString.insert(0, "SELECT COUNT(subject_id) FROM ("); queryString.append(") count_subject_id"); Query countQuery = entityManager.createNativeQuery(queryString.toString()); fillWithParameters(countQuery, parameters); LOG.debug("Native count query\n{}\nwith parameters\n{}", queryString.toString(), parameters); int result = ((Number) countQuery.getSingleResult()).intValue(); LOG.debug("Native count query result: {}", result); return result; }
From source file:com.emc.ecs.sync.test.TestObjectTarget.java
private synchronized List<TestSyncObject> getChildren(String relativePath) { List<TestSyncObject> children = childrenMap.get(relativePath); if (children == null) { children = Collections.synchronizedList(new ArrayList<TestSyncObject>()); childrenMap.put(relativePath, children); }/* w ww . j av a2s .c o m*/ return children; }
From source file:org.protempa.Executor.java
Executor(Query query, Destination resultsHandlerFactory, QuerySession querySession, ExecutorStrategy strategy, AbstractionFinder abstractionFinder) throws QueryException { this.abstractionFinder = abstractionFinder; assert query != null : "query cannot be null"; assert resultsHandlerFactory != null : "resultsHandlerFactory cannot be null"; assert abstractionFinder != null : "abstractionFinder cannot be null"; if (abstractionFinder.isClosed()) { throw new QueryException(query.getName(), new ProtempaAlreadyClosedException()); }//from w w w.ja va 2s.c o m this.keyIds = Arrays.asSet(query.getKeyIds()); this.propIds = Arrays.asSet(query.getPropositionIds()); this.termIds = Arrays.asSet(query.getTermIds()); this.filters = query.getFilters(); this.propDefs = query.getPropositionDefinitions(); if (propDefs != null && propDefs.length > 0) { ks = new KnowledgeSourceImplWrapper(abstractionFinder.getKnowledgeSource(), propDefs); } else { ks = abstractionFinder.getKnowledgeSource(); } this.query = query; this.qs = querySession; this.derivationsBuilder = new DerivationsBuilder(); this.strategy = strategy; this.destination = resultsHandlerFactory; this.exceptions = Collections.synchronizedList(new ArrayList<QueryException>()); this.logMessageFormat = new MessageFormat("Query " + this.query.getName() + ": {0}"); }