AGGREGATOR getAndReset(Updater<AGGREGATOR, SAMPLE> updater) { AGGREGATOR previous; synchronized (lock) { previous = current; current = updater.createGenerationInstance(previous); setRegistered(false); } return previous; }
boolean update(SAMPLE x, Updater<AGGREGATOR, SAMPLE> updater) { synchronized (lock) { current = updater.update(current, x); return isRegistered; } }
/** * Returns an iterator over the elements of this, starting at the last * element and working backwards. This iterator does not support remove. */ public Iterator<T> reverseIterator() { return new ThreadRobustReverseIterator(items); }
/** * Registers a protocol with this repository. This will overwrite any protocol that was registered earlier that has * the same name. If this method detects a protocol replacement, it will clear its internal routing policy cache. * * @param protocol The protocol to register. */ public void putProtocol(Protocol protocol) { if (protocols.put(protocol.getName(), protocol) != null) { routingPolicyCache.clear(); } }
/** * Returns the protocol whose name matches the given argument. This method will return null if no such protocol has * been registered. * * @param name The name of the protocol to return. * @return The protocol registered, or null. */ public Protocol getProtocol(String name) { return protocols.get(name); }
public void put(Integer index, String target) { targets.put(index, target); } }
/** * Input data from a producer thread. * * @param x * the data to insert */ public void update(SAMPLE x) { update(x, getOrCreateLocal()); }
/** * Constructs a new instance of this class to maintain sending of a single message. * * @param mbus The message bus that owns this. * @param net The network layer to transmit through. * @param resender The resender to use. */ public SendProxy(MessageBus mbus, Network net, Resender resender) { this.mbus = mbus; this.net = net; this.resender = resender; sendTime = SystemTimer.INSTANCE.milliTime(); }
/** * Constructs a new instance of this class using the given clock to calculate efficiency. * * @param timer the timer to use */ public DynamicThrottlePolicy(Timer timer) { this.timer = timer; this.timeOfLastMessage = timer.milliTime(); }
/** * Returns whether or not this repository contains a protocol with the given name. Given the concurrent nature of * things, one should not invoke this method followed by {@link #getProtocol(String)} and expect the return value to * be non-null. Instead just get the protocol and compare it to null. * * @param name The name to check for. * @return True if the named protocol is registered. */ public boolean hasProtocol(String name) { return protocols.containsKey(name); }
/** Locks key. This will block until the key is acquired or the default timeout is reached. */ public Lock lock(TYPE key) { return lock(key, timeoutMs, TimeUnit.MILLISECONDS); }
static public synchronized ThreadFactory getDaemonThreadFactory(String name) { PooledFactory p = factory.get(name); if (p == null) { p = new PooledFactory(name); factory.put(name, p); } return p.getFactory(true); } private static class PooledFactory {
/** * Expose the thread local for the running thread, for use in conjunction * with update(SAMPLE, LocalInstance<AGGREGATOR, SAMPLE>). * * @return the current thread's local instance */ public LocalInstance<AGGREGATOR, SAMPLE> getLocalInstance() { return getOrCreateLocal(); }
AGGREGATOR copyCurrent(ObservableUpdater<AGGREGATOR, SAMPLE> updater) { AGGREGATOR view; synchronized (lock) { view = updater.copy(current); } return view; }
/** * Returns an iterator over the elements of this. This iterator does not * support remove. */ @Override public Iterator<T> iterator() { return new ThreadRobustIterator(items); }
@Override public void release() { if (lock != null) lock.close(); }
LocalInstance(Updater<AGGREGATOR, SAMPLE> updater) { current = updater.createGenerationInstance(null); }
public String get(Integer index) { return targets.get(index); } public void put(Integer index, String target) {
/** * <p>Returns the number of milliseconds that remain right now before this message times out. This is a function of * {@link #getTimeReceived()}, {@link #getTimeRemaining()} and current time. Whenever a message is transmitted by * message bus, a new remaining time is calculated and serialized as <code>timeRemaining = timeRemaining - * (currentTime - timeReceived)</code>. This means that we are doing an over-estimate of remaining time, as we are * only factoring in the time used by the application above message bus.</p> * * @return The remaining time in milliseconds. */ public long getTimeRemainingNow() { return timeRemaining - (SystemTimer.INSTANCE.milliTime() - timeReceived); }
public RateThrottlingPolicy(double desiredRate, Timer timer) { this.desiredRate = desiredRate; this.timer = timer; currentPeriod = timer.milliTime() / PERIOD; }