/** * Reinitialize the extension point plugins map */ public void reInitialize() { lock.writeLock().lock(); try { extensionPointPluginMap = HashBasedTable.create(); final PluginRegistry registry = PluginRegistry.getInstance(); List<PluginInterface> extensionPointPlugins = registry.getPlugins( ExtensionPointPluginType.class ); for ( PluginInterface extensionPointPlugin : extensionPointPlugins ) { addExtensionPoint( extensionPointPlugin ); } } finally { lock.writeLock().unlock(); } }
/** Creates an empty {@code HashBasedTable}. */ public static <R, C, V> HashBasedTable<R, C, V> create() { return new HashBasedTable<>(new LinkedHashMap<R, Map<C, V>>(), new Factory<C, V>(0)); }
/** * Creates a {@code HashBasedTable} with the same mappings as the specified table. * * @param table the table to copy * @throws NullPointerException if any of the row keys, column keys, or values in {@code table} is * null */ public static <R, C, V> HashBasedTable<R, C, V> create( Table<? extends R, ? extends C, ? extends V> table) { HashBasedTable<R, C, V> result = create(); result.putAll(table); return result; }
/** * Add an entry to the AdjacencyMap. * * @param source the source vertex * @param destination the destination vertex * @param edge the edge to add * * @return the {@link Set} containing the edge objects associated with the * source and destination vertices */ public Set<Edge> putEdge(final Object source, final Object destination, final Edge edge) { final Set<Edge> existing = edgeGraph.get(source, destination); if (null == existing) { final Set<Edge> set = Sets.newHashSet(edge); return edgeGraph.put(source, destination, set); } else { existing.add(edge); return existing; } }
/** * Creates a new instance of {@link ServerObservationHandler} * * @param executor the {@link ScheduledExecutorService} to handle internal tasks such as sending update * notifications */ public ServerObservationHandler(ScheduledExecutorService executor) { super(executor); this.observations1 = HashBasedTable.create(); this.observations2 = HashBasedTable.create(); this.lock = new ReentrantReadWriteLock(); }
private ClientCallback updateCallback(InetSocketAddress remoteSocket, InetSocketAddress previous, Token token) { try { this.lock.readLock().lock(); if (getCallback(previous, token) == null) { return null; } } finally { this.lock.readLock().unlock(); } try { this.lock.writeLock().lock(); ClientCallback callback = this.clientCallbacks.remove(previous, token); if (callback != null) { this.clientCallbacks.put(remoteSocket, token, callback); log.info("Updated remote socket (old: \"{}\", new: \"{}\")", previous, remoteSocket); } return callback; } finally { this.lock.writeLock().unlock(); } }
protected void addToAssignedByMe(InetSocketAddress remoteSocket, Token token, EndpointID endpointID) { try { this.lock.writeLock().lock(); this.assignedByMe1.put(endpointID, token, remoteSocket); this.assignedByMe2.put(remoteSocket, token, endpointID); LOG.info("Added ID to identify remote host {}: {}", remoteSocket, endpointID); } finally { this.lock.writeLock().unlock(); } }
private void addCallback(InetSocketAddress remoteSocket, Token token, ClientCallback clientCallback) { try { this.lock.readLock().lock(); if (this.clientCallbacks.contains(remoteSocket, token)) { log.error("Tried to use token twice (remote endpoint: {}, token: {})", remoteSocket, token); return; } } finally { this.lock.readLock().unlock(); } try { this.lock.writeLock().lock(); if (this.clientCallbacks.contains(remoteSocket, token)) { log.error("Tried to use token twice (remote endpoint: {}, token: {})", remoteSocket, token); } else { clientCallbacks.put(remoteSocket, token, clientCallback); log.info("Added callback (remote endpoint: {}, token: {})", remoteSocket, token); if (this.clientCallbacks.size() > 1000) { log.error("More than 1000 callbacks!"); } } } finally { this.lock.writeLock().unlock(); } }
private ChannelBuffer addRequestBlock(CoapRequest coapRequest, InetSocketAddress remoteSocket) { try { this.lock.writeLock().lock(); // lookup previously received blocks and append actual block Token token = coapRequest.getToken(); ChannelBuffer receivedBlocks = this.receivedRequestBlocks.get(remoteSocket, token); if (receivedBlocks == null) { receivedBlocks = coapRequest.getContent(); } else { receivedBlocks = ChannelBuffers.wrappedBuffer(receivedBlocks, coapRequest.getContent()); } this.receivedRequestBlocks.put(remoteSocket, token, receivedBlocks); return receivedBlocks; } finally { this.lock.writeLock().unlock(); } }
@Override protected Collection<String> create(String[] elements) { Table<Integer, Character, String> table = HashBasedTable.create(); table.put(1, 'a', "foo"); table.clear(); populateForValues(table, elements); return Tables.unmodifiableTable(table).values(); } })
@Override protected Collection<String> create(String[] elements) { Table<Integer, Character, String> table = HashBasedTable.create(); for (int i = 0; i < elements.length; i++) { table.put(i, 'a', "x" + checkNotNull(elements[i])); } return Tables.transformValues(table, removeFirstCharacter).values(); } })
@Override protected Map<String, Integer> makePopulatedMap() { Table<String, Character, Integer> table = HashBasedTable.create(); table.put("one", 'a', 1); table.put("two", 'a', 2); table.put("three", 'a', 3); table.put("four", 'b', 4); return Tables.transformValues(table, DIVIDE_BY_2).column('a'); } }