public void testWhenTrue() throws InterruptedException { final WaitableBoolean blocker = new WaitableBoolean(false); final WaitableBoolean actionPerformed = new WaitableBoolean(false); Runnable switcher = new Runnable() { public void run() { try { Thread.sleep(500); blocker.set(true); } catch (InterruptedException iex) { // ignore } } }; Runnable action = new Runnable() { public void run() { actionPerformed.set(true); } }; new Thread(switcher).start(); blocker.whenTrue(action); assertTrue(blocker.get()); assertTrue(actionPerformed.get()); }
public void testComplement() { assertFalse(TRUE.complement()); assertFalse(TRUE.get()); assertTrue(FALSE.complement()); assertTrue(FALSE.get()); }
public void testCommit() { assertTrue(TRUE.commit(true, true)); assertTrue(TRUE.get()); assertFalse(TRUE.commit(false, true)); assertTrue(TRUE.commit(true, false)); assertFalse(TRUE.get()); assertTrue(TRUE.commit(false, true)); assertTrue(TRUE.get()); }
public void testOr() { assertTrue((new WaitableBoolean(true)).or(true)); assertTrue((new WaitableBoolean(true)).or(false)); assertFalse((new WaitableBoolean(false)).or(false)); assertTrue((new WaitableBoolean(false)).or(true)); assertTrue(TRUE.or(true)); assertTrue(TRUE.get()); assertTrue(TRUE.or(false)); assertTrue(TRUE.get()); }
public void testAnd() { assertTrue((new WaitableBoolean(true)).and(true)); assertFalse((new WaitableBoolean(true)).and(false)); assertFalse((new WaitableBoolean(false)).and(false)); assertFalse((new WaitableBoolean(false)).and(true)); assertTrue(TRUE.and(true)); assertTrue(TRUE.get()); assertFalse(TRUE.and(false)); assertFalse(TRUE.get()); }
public void testWhenTrueAlreadyTrue() throws InterruptedException { final WaitableBoolean blocker = new WaitableBoolean(true); final WaitableBoolean actionPerformed = new WaitableBoolean(false); Runnable action = new Runnable() { public void run() { actionPerformed.set(true); } }; blocker.whenTrue(action); assertTrue(blocker.get()); assertTrue(actionPerformed.get()); }
public final synchronized void connect() throws Exception { // This method may be called to ensure transport is connected, if it is // already connected then just return. if (connected.get()) { return; } if (disposed.get()) { throw new IllegalStateException( "Requester/dispatcher has been disposed; cannot connect to resource"); } retryTemplate.execute( new RetryCallback() { public void doWork(RetryContext context) throws Exception { try { doConnect(); connected.set(true); if (startOnConnect) { start(); } } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug(e); } throw e; } } public String getWorkDescription() { return getConnectionDescription(); } }, getWorkManager()); }
public void dispatchEvent(MuleEvent event) throws MuleException { if (stopping.get() || stopped.get()) { throw new ServiceException(CoreMessages.componentIsStopped(name), event.getMessage(), this); } // Dispatching event to an inbound endpoint // in the DefaultMuleSession#dispatchEvent ImmutableEndpoint endpoint = event.getEndpoint(); if (endpoint instanceof OutboundEndpoint) { try { ((OutboundEndpoint) endpoint).dispatch(event); } catch (Exception e) { throw new DispatchException(event.getMessage(), event.getEndpoint(), e); } return; } if (logger.isDebugEnabled()) { logger.debug( "Service: " + name + " has received asynchronous event on: " + event.getEndpoint().getEndpointURI()); } // Dispatching event to the service if (stats.isEnabled()) { stats.incReceivedEventASync(); } doDispatch(event); }
public final void start() throws MuleException { if (!connected.get()) { startOnConnect = true; // Make sure we are connected try { connect(); } catch (Exception e) { throw new LifecycleException(e, this); } return; } if (stopped.compareAndSet(true, false)) { doStart(); } }
public final synchronized void disconnect() throws Exception { if (!connected.get()) { return; } if (logger.isDebugEnabled()) { logger.debug("Disconnecting: " + this); } this.doDisconnect(); connected.set(false); logger.info("Disconnected: " + this); connector.fireNotification( new ConnectionNotification( this, getConnectEventId(endpoint), ConnectionNotification.CONNECTION_DISCONNECTED)); }
public final void stop() { try { if (connected.get()) { disconnect(); } } catch (Exception e) { // TODO MULE-863: What should we really do? logger.error(e.getMessage(), e); } if (stopped.compareAndSet(false, true)) { try { doStop(); } catch (MuleException e) { // TODO MULE-863: What should we really do? logger.error(e.getMessage(), e); } } }
public MuleMessage sendEvent(MuleEvent event) throws MuleException { if (stopping.get() || stopped.get()) { throw new ServiceException(CoreMessages.componentIsStopped(name), event.getMessage(), this); } try { waitIfPaused(event); } catch (InterruptedException e) { throw new ServiceException(event.getMessage(), this, e); } if (stats.isEnabled()) { stats.incReceivedEventSync(); } if (logger.isDebugEnabled()) { logger.debug( "Service: " + name + " has received synchronous event on: " + event.getEndpoint().getEndpointURI()); } event = OptimizedRequestContext.unsafeSetEvent(event); return doSend(event); }
public boolean isStopping() { return stopping.get(); }
/** * Called before an event is sent or dispatched to a service, it will block until resume() is * called. Users can override this method if they want to handle pausing differently e.g. * implement a store and forward policy * * @param event the current event being passed to the service * @throws InterruptedException if the thread is interrupted */ protected void waitIfPaused(MuleEvent event) throws InterruptedException { if (logger.isDebugEnabled() && paused.get()) { logger.debug("Service: " + name + " is paused. Blocking call until resume is called"); } paused.whenFalse(null); }
/** * Determines if the service is in a paused state * * @return True if the service is in a paused state, false otherwise */ public boolean isPaused() { return paused.get(); }
public boolean isStarted() { return !stopped.get(); }
public void testGet() { assertTrue(TRUE.get()); assertFalse(FALSE.get()); }
public final boolean isConnected() { return connected.get(); }