Refine search
@Override public void run() { try { function.apply(entry.listener); } catch ( Throwable e ) { ThreadUtils.checkInterrupted(e); log.error(String.format("Listener (%s) threw an exception", entry.listener), e); } } }
/** * @param client the client * @param threadFactory thread factory to use or null for a default * @param sessionTimeoutMs the ZK session timeout in milliseconds * @param sessionExpirationPercent percentage of negotiated session timeout to use when simulating a session timeout. 0 means don't simulate at all */ public ConnectionStateManager(CuratorFramework client, ThreadFactory threadFactory, int sessionTimeoutMs, int sessionExpirationPercent) { this.client = client; this.sessionTimeoutMs = sessionTimeoutMs; this.sessionExpirationPercent = sessionExpirationPercent; if ( threadFactory == null ) { threadFactory = ThreadUtils.newThreadFactory("ConnectionStateManager"); } service = Executors.newSingleThreadExecutor(threadFactory); }
private static ScheduledExecutorService newExecutorService() { return ThreadUtils.newFixedThreadScheduledPool(2, "ChildReaper"); }
@Override public void process(WatchedEvent event) { if ( (state.get() == State.STARTED) && (event.getType() == Event.EventType.NodeDeleted) && (localOurPath != null) ) { try { getChildren(); } catch ( Exception ex ) { ThreadUtils.checkInterrupted(ex); log.error("An error occurred checking the leadership.", ex); } } } };
private void createNode() { if ( !isActive() ) { return; } try { String existingPath = nodePath.get(); String createPath = (existingPath != null && !useProtection) ? existingPath : basePath; CreateModable<ACLBackgroundPathAndBytesable<String>> localCreateMethod = createMethod.get(); if ( localCreateMethod == null ) { CreateModable<ACLBackgroundPathAndBytesable<String>> tempCreateMethod = useProtection ? client.create().creatingParentContainersIfNeeded().withProtection() : client.create().creatingParentContainersIfNeeded(); if ( createMethod.compareAndSet(null, tempCreateMethod) ) { localCreateMethod = tempCreateMethod; } } localCreateMethod.withMode(getCreateMode(existingPath != null)).inBackground(backgroundCallback).forPath(createPath, data.get()); } catch ( Exception e ) { ThreadUtils.checkInterrupted(e); throw new RuntimeException("Creating node. BasePath: " + basePath, e); // should never happen unless there's a programming error - so throw RuntimeException } }
if ( !state.compareAndSet(CuratorFrameworkState.LATENT, CuratorFrameworkState.STARTED) ) ThreadUtils.checkInterrupted(e); handleBackgroundOperationException(null, e);
private synchronized void openConnectionIfNeeded() throws Exception { if ( client == null ) { client = (CuratorFrameworkImpl)factory.build(); // cast is safe - we control both sides of this client.start(); } if ( cleanup == null ) { ThreadFactory threadFactory = factory.getThreadFactory(); if (threadFactory == null) { threadFactory = ThreadUtils.newGenericThreadFactory("CuratorTempFrameworkImpl"); } cleanup = Executors.newScheduledThreadPool(1, threadFactory); Runnable command = new Runnable() { @Override public void run() { checkInactive(); } }; cleanup.scheduleAtFixedRate(command, inactiveThresholdMs, inactiveThresholdMs, TimeUnit.MILLISECONDS); } updateLastAccess(); }
final ExecutorService executor = ThreadUtils.newSingleThreadExecutor(ThreadUtils.getProcessName(runAfterConnection.getClass())); Runnable internalCall = new Runnable()
public static String getProcessName(Class<?> clazz) { if ( clazz.isAnonymousClass() ) { return getProcessName(clazz.getEnclosingClass()); } return clazz.getSimpleName(); } }
@Override public CachedModeledFramework<T> cached() { return cached(ThreadUtils.newSingleThreadExecutor("CachedModeledFramework")); }
private synchronized void internalStart() { if ( state.get() == State.STARTED ) { client.getConnectionStateListenable().addListener(listener); try { reset(); } catch ( Exception e ) { ThreadUtils.checkInterrupted(e); log.error("An error occurred checking resetting leadership.", e); } } }
@Override public void close() throws IOException { if ( !state.compareAndSet(State.STARTED, State.CLOSED) ) { return; } client.getConnectionStateListenable().removeListener(connectionStateListener); try { deleteNode(); } catch ( Exception e ) { ThreadUtils.checkInterrupted(e); throw new IOException(e); } }
public static ThreadFactory newThreadFactory(String processName) { return newGenericThreadFactory("Curator-" + processName); }
public static String getProcessName(Class<?> clazz) { if ( clazz.isAnonymousClass() ) { return getProcessName(clazz.getEnclosingClass()); } return clazz.getSimpleName(); } }
@Override public void run() { try { operationsQuantizer.remove(operation); operation.invoke(); } catch ( InterruptedException e ) { //We expect to get interrupted during shutdown, //so just ignore these events if ( state.get() != State.CLOSED ) { handleException(e); } Thread.currentThread().interrupt(); } catch ( Exception e ) { ThreadUtils.checkInterrupted(e); handleException(e); } } }
if ( !state.compareAndSet(CuratorFrameworkState.LATENT, CuratorFrameworkState.STARTED) ) ThreadUtils.checkInterrupted(e); handleBackgroundOperationException(null, e);
@Override public Void apply(CuratorListener listener) { CuratorEvent event = new CuratorEventImpl(CuratorFrameworkImpl.this, CuratorEventType.CLOSING, 0, null, null, null, null, null, null, null, null, null); try { listener.eventReceived(CuratorFrameworkImpl.this, event); } catch ( Exception e ) { ThreadUtils.checkInterrupted(e); log.error("Exception while sending Closing event", e); } return null; } });
private ThreadFactory getThreadFactory(CuratorFrameworkFactory.Builder builder) { ThreadFactory threadFactory = builder.getThreadFactory(); if ( threadFactory == null ) { threadFactory = ThreadUtils.newThreadFactory("Framework"); } return threadFactory; }
private static ScheduledExecutorService newExecutorService() { return ThreadUtils.newFixedThreadScheduledPool(2, "ChildReaper"); }
public static ThreadFactory newThreadFactory(String processName) { return newGenericThreadFactory("Curator-" + processName); }