/** * Returns {@code true} if this set contains no elements. * * @return {@code true} if this set contains no elements */ public boolean isEmpty() { return al.isEmpty(); }
public boolean hasSubscriberForEvent(Class<?> eventClass) { List<Class<?>> eventTypes = lookupAllEventTypes(eventClass); if (eventTypes != null) { int countTypes = eventTypes.size(); for (int h = 0; h < countTypes; h++) { Class<?> clazz = eventTypes.get(h); CopyOnWriteArrayList<Subscription> subscriptions; synchronized (this) { subscriptions = subscriptionsByEventType.get(clazz); } if (subscriptions != null && !subscriptions.isEmpty()) { return true; } } } return false; }
private boolean postSingleEventForEventType(Object event, PostingThreadState postingState, Class<?> eventClass) { CopyOnWriteArrayList<Subscription> subscriptions; synchronized (this) { subscriptions = subscriptionsByEventType.get(eventClass); } if (subscriptions != null && !subscriptions.isEmpty()) { for (Subscription subscription : subscriptions) { postingState.event = event; postingState.subscription = subscription; boolean aborted = false; try { postToSubscription(subscription, event, postingState.isMainThread); aborted = postingState.canceled; } finally { postingState.event = null; postingState.subscription = null; postingState.canceled = false; } if (aborted) { break; } } return true; } return false; }
private void sendProcedureLoadedNotification(final long procId) { if (!this.listeners.isEmpty()) { for (ProcedureExecutorListener listener: this.listeners) { try { listener.procedureLoaded(procId); } catch (Throwable e) { LOG.error("Listener " + listener + " had an error: " + e.getMessage(), e); } } } }
private void sendProcedureAddedNotification(final long procId) { if (!this.listeners.isEmpty()) { for (ProcedureExecutorListener listener: this.listeners) { try { listener.procedureAdded(procId); } catch (Throwable e) { LOG.error("Listener " + listener + " had an error: " + e.getMessage(), e); } } } }
private void sendProcedureFinishedNotification(final long procId) { if (!this.listeners.isEmpty()) { for (ProcedureExecutorListener listener: this.listeners) { try { listener.procedureFinished(procId); } catch (Throwable e) { LOG.error("Listener " + listener + " had an error: " + e.getMessage(), e); } } } }
/** * Check elapsed time since last refresh and only refresh if time difference is * greater than threshold. */ private void refreshIfElapsed() { long currentTime = System.currentTimeMillis(); if (currentTime - _lastRefreshedTime > _refreshMs && !_counters.isEmpty()) { refresh(); _lastRefreshedTime = currentTime; } }
private boolean unsubscribe(String queryName, QuerySubscription querySubscription) { subscriptions.computeIfPresent(queryName, (key, handlers) -> { handlers.remove(querySubscription); if (handlers.isEmpty()) { return null; } return handlers; }); return true; }
/** * Returns true if all the executors of this computer are idle. */ @Exported public final boolean isIdle() { if (!oneOffExecutors.isEmpty()) return false; for (Executor e : executors) if(!e.isIdle()) return false; return true; }
public MappedFile getLastMappedFile() { MappedFile mappedFileLast = null; while (!this.mappedFiles.isEmpty()) { try { mappedFileLast = this.mappedFiles.get(this.mappedFiles.size() - 1); break; } catch (IndexOutOfBoundsException e) { //continue; } catch (Exception e) { log.error("getLastMappedFile has exception.", e); break; } } return mappedFileLast; }
@SuppressWarnings("unchecked") public <E extends Throwable> E expectError(Class<E> clazz, long timeoutMillis, String errorMsg) throws Exception { Thread.sleep(timeoutMillis); if (env.asyncErrors.isEmpty()) { return env.flopAndFail(String.format("%s within %d ms", errorMsg, timeoutMillis)); } else { // ok, there was an expected error Throwable thrown = env.asyncErrors.remove(0); if (clazz.isInstance(thrown)) { return (E) thrown; } else { return env.flopAndFail(String.format("%s within %d ms; Got %s but expected %s", errorMsg, timeoutMillis, thrown.getClass().getCanonicalName(), clazz.getCanonicalName())); } } }
public MappedFile getFirstMappedFile() { MappedFile mappedFileFirst = null; if (!this.mappedFiles.isEmpty()) { try { mappedFileFirst = this.mappedFiles.get(0); } catch (IndexOutOfBoundsException e) { //ignore } catch (Exception e) { log.error("getFirstMappedFile has exception.", e); } } return mappedFileFirst; }
@Restricted(NoExternalUse.class) public Object readResolve() { if (views == null) // this shouldn't happen, but an error in 1.319 meant the last view could be deleted views = new CopyOnWriteArrayList<View>(); if (views.isEmpty()) { // preserve the non-empty invariant views.add(new AllView(AllView.DEFAULT_VIEW_NAME, this)); } if (primaryViewName != null) { // It may happen when the default constructor is invoked primaryViewName = AllView.migrateLegacyPrimaryAllViewLocalizedName(views, primaryViewName); } viewGroupMixIn = new ViewGroupMixIn(this) { protected List<View> views() { return views; } protected String primaryView() { return primaryViewName; } protected void primaryView(String name) { primaryViewName=name; } }; return this; }
/** {@inheritDoc} */ @Override public void close() { assert inputs.get() == 0 : inputs.get(); assert adders.isEmpty() : adders.size(); state(State.READING_WRITING, State.CLOSING); if (keys() == 0) return; super.close(); }
public long howMuchFallBehind() { if (this.mappedFiles.isEmpty()) return 0; long committed = this.flushedWhere; if (committed != 0) { MappedFile mappedFile = this.getLastMappedFile(0, false); if (mappedFile != null) { return (mappedFile.getFileFromOffset() + mappedFile.getWrotePosition()) - committed; } } return 0; }
public long getMinOffset() { if (!this.mappedFiles.isEmpty()) { try { return this.mappedFiles.get(0).getFileFromOffset(); } catch (IndexOutOfBoundsException e) { //continue; } catch (Exception e) { log.error("getMinOffset has exception.", e); } } return -1; }
void notifyChanges(ImmutableSet<DLSocketAddress> addresses) { if (monitors.isEmpty()) { changeQueue.add(addresses); } else { for (ServerSetMonitor monitor : monitors) { monitor.onChange(addresses); } } } }
public void checkSelf() { if (!this.mappedFiles.isEmpty()) { Iterator<MappedFile> iterator = mappedFiles.iterator(); MappedFile pre = null; while (iterator.hasNext()) { MappedFile cur = iterator.next(); if (pre != null) { if (cur.getFileFromOffset() - pre.getFileFromOffset() != this.mappedFileSize) { LOG_ERROR.error("[BUG]The mappedFile queue's data is damaged, the adjacent mappedFile's offset don't match. pre file {}, cur file {}", pre.getFileName(), cur.getFileName()); } } pre = cur; } } }
@Override public boolean remove(JChannel channel) { boolean removed = channel instanceof NettyChannel && channels.remove(channel); if (removed) { timestamp = SystemClock.millisClock().now(); // reset timestamp if (channels.isEmpty()) { deadlineMillis = SystemClock.millisClock().now() + LOSS_INTERVAL; } } return removed; }
@Override public boolean remove(JChannel channel) { boolean removed = channel instanceof NettyChannel && channels.remove(channel); if (removed) { timestamp = SystemClock.millisClock().now(); // reset timestamp if (channels.isEmpty()) { deadlineMillis = SystemClock.millisClock().now() + LOSS_INTERVAL; } } return removed; }