Examples of AtomicReference


Examples of java.util.concurrent.atomic.AtomicReference

    }

    public void testSend() throws Exception
    {
        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference message = new AtomicReference();

        EventCallback callback = new EventCallback()
        {
            public synchronized void eventReceived(MuleEventContext context, Object component)
            {
                try
                {
                    FunctionalStreamingTestComponent ftc = (FunctionalStreamingTestComponent) component;
                    message.set(ftc.getSummary());
                    latch.countDown();
                }
                catch (Exception e)
                {
                    logger.error(e.getMessage(), e);
                }
            }
        };

        Object ftc = getComponent("testComponent");
        assertTrue("FunctionalStreamingTestComponent expected",
            ftc instanceof FunctionalStreamingTestComponent);
        assertNotNull(ftc);
        ((FunctionalStreamingTestComponent) ftc).setEventCallback(callback, size);

        Runtime runtime = Runtime.getRuntime();
        runtime.gc(); // i know, i know...
        long freeStart = runtime.freeMemory();
        long maxStart = runtime.maxMemory();
        long timeStart = System.currentTimeMillis();

        BigInputStream stream = new BigInputStream(size, MESSAGES);
        MuleClient client = new MuleClient(muleContext);
        // dynamically get the endpoint to send to
        client.dispatch(
            ((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("testInbound")).getAddress(),
            new DefaultMuleMessage(stream, muleContext));

        // if we assume 1MB/sec then we need at least...
        long pause = Math.max(size / ONE_MB, 60 * 10) + 10;
        logger.info("Waiting for up to " + pause + " seconds");

        latch.await(pause, TimeUnit.SECONDS);
        assertEquals(stream.summary(), message.get());

        // neither of these memory tests are really reliable, but if we stay with 1.4
        // i don't
        // know of anything better.
        // if these fail in practice i guess we just remove them.
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

    }

    public void testSend() throws Exception
    {
        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference message = new AtomicReference();
        final AtomicInteger loopCount = new AtomicInteger(0);

        EventCallback callback = new EventCallback()
        {
            public synchronized void eventReceived(MuleEventContext context, Object component)
            {
                try
                {
                    logger.info("called " + loopCount.incrementAndGet() + " times");
                    FunctionalStreamingTestComponent ftc = (FunctionalStreamingTestComponent) component;
                    // without this we may have problems with the many repeats
                    if (1 == latch.getCount())
                    {
                        message.set(ftc.getSummary());
                        assertEquals(RESULT, message.get());
                        latch.countDown();
                    }
                }
                catch (Exception e)
                {
                    logger.error(e.getMessage(), e);
                }
            }
        };

        MuleClient client = new MuleClient(muleContext);

        // this works only if singleton set in descriptor
        Object ftc = getComponent("testComponent");
        assertTrue("FunctionalStreamingTestComponent expected", ftc instanceof FunctionalStreamingTestComponent);
        assertNotNull(ftc);

        ((FunctionalStreamingTestComponent) ftc).setEventCallback(callback, TEST_MESSAGE.length());

        client.dispatch(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("testInbound")).getAddress(),
            TEST_MESSAGE, new HashMap());

        latch.await(10, TimeUnit.SECONDS);
        assertEquals(RESULT, message.get());
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

    @SuppressWarnings("rawtypes")
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
        Object item;
        if (object instanceof AtomicReference) {
            AtomicReference val = (AtomicReference) object;
            item = val.get();
        } else {
            item = ((Reference) object).get();
        }
        serializer.write(item);
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

        Object itemObject = parser.parseObject(itemType);

        Type rawType = paramType.getRawType();
        if (rawType == AtomicReference.class) {
            return (T) new AtomicReference(itemObject);
        }

        if (rawType == WeakReference.class) {
            return (T) new WeakReference(itemObject);
        }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

        EasyMock.verify(new Object[]{mockConfiguration, mockConfigurationAdmin, mockBundleContext});
    }
   
    public void testShouldSaveConfig()
    {
        final AtomicReference disable = new AtomicReference();
        final AtomicReference enable = new AtomicReference();
       
        EasyMock.expect(mockBundleContext.getProperty(DirectoryWatcher.DISABLE_CONFIG_SAVE)).andAnswer(
                new IAnswer() {
                    public Object answer() throws Throwable {
                        return disable.get() != null ? disable.get().toString() : null;
                    }
                }
        ).anyTimes();
        EasyMock.expect(mockBundleContext.getProperty(DirectoryWatcher.ENABLE_CONFIG_SAVE)).andAnswer(
                new IAnswer() {
                    public Object answer() throws Throwable {
                        return enable.get() != null ? enable.get().toString() : null;
                    }
                }
        ).anyTimes();
        EasyMock.replay(new Object[]{mockConfiguration, mockConfigurationAdmin, mockBundleContext});

        ConfigInstaller ci = new ConfigInstaller( mockBundleContext, mockConfigurationAdmin, new FileInstall() );

        disable.set(null);
        enable.set(null);
        assertTrue( ci.shouldSaveConfig() );

        disable.set(Boolean.FALSE);
        enable.set(null);
        assertFalse( ci.shouldSaveConfig() );

        disable.set(Boolean.TRUE);
        enable.set(null);
        assertTrue( ci.shouldSaveConfig() );

        disable.set(null);
        enable.set(Boolean.FALSE);
        assertFalse( ci.shouldSaveConfig() );

        disable.set(Boolean.FALSE);
        enable.set(Boolean.FALSE);
        assertFalse( ci.shouldSaveConfig() );

        disable.set(Boolean.TRUE);
        enable.set(Boolean.FALSE);
        assertFalse( ci.shouldSaveConfig() );

        disable.set(null);
        enable.set(Boolean.TRUE);
        assertTrue( ci.shouldSaveConfig() );

        disable.set(Boolean.FALSE);
        enable.set(Boolean.TRUE);
        assertTrue( ci.shouldSaveConfig() );

        disable.set(Boolean.TRUE);
        enable.set(Boolean.TRUE);
        assertTrue( ci.shouldSaveConfig() );

        EasyMock.verify(new Object[]{mockConfiguration, mockConfigurationAdmin, mockBundleContext});
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

final public class Atom extends ARef{
final AtomicReference state;

public Atom(Object state){
  this.state = new AtomicReference(state);
}
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

  this.state = new AtomicReference(state);
}

public Atom(Object state, IPersistentMap meta){
  super(meta);
  this.state = new AtomicReference(state);
}
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

            {
                try
                {
                    try
                    {
                        final AtomicReference exceptionThrownDuringFlowProcessing = new AtomicReference();
                        TransactionalErrorHandlingExecutionTemplate transactionTemplate = TransactionalErrorHandlingExecutionTemplate.
                                createMainExecutionTemplate(messageProcessContext.getFlowConstruct().getMuleContext(),
                                                            (messageProcessContext.getTransactionConfig() == null ? new MuleTransactionConfig() : messageProcessContext.getTransactionConfig()),
                                                            messageProcessContext.getFlowConstruct().getExceptionListener());
                        MuleEvent response = transactionTemplate.execute(new ExecutionCallback<MuleEvent>()
                        {
                            @Override
                            public MuleEvent process() throws Exception
                            {
                                try
                                {
                                    Object message = flowProcessingPhaseTemplate.getOriginalMessage();
                                    if (message == null)
                                    {
                                        return null;
                                    }
                                    MuleEvent muleEvent = flowProcessingPhaseTemplate.getMuleEvent();
                                    muleEvent = flowProcessingPhaseTemplate.beforeRouteEvent(muleEvent);
                                    muleEvent = flowProcessingPhaseTemplate.routeEvent(muleEvent);
                                    muleEvent = flowProcessingPhaseTemplate.afterRouteEvent(muleEvent);
                                    sendResponseIfNeccessary(muleEvent, flowProcessingPhaseTemplate);
                                    return muleEvent;
                                }
                                catch (Exception e)
                                {
                                    exceptionThrownDuringFlowProcessing.set(e);
                                    throw e;
                                }
                            }
                        });
                        if (exceptionThrownDuringFlowProcessing.get() != null && !(exceptionThrownDuringFlowProcessing.get() instanceof ResponseDispatchException))
                        {
                            sendResponseIfNeccessary(response, flowProcessingPhaseTemplate);
                        }
                        flowProcessingPhaseTemplate.afterSuccessfulProcessingFlow(response);
                    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

    private AtomicReference[] a = new AtomicReference[100];

    public PacketStatisticsTracker() {
        for (int i = 0; i < 100; ++i) {
            this.a[i] = new AtomicReference(new PackStatisticData(0L, 0, 0.0D, (ModdingApi) null));
        }
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

            // Resource can be null if the client disconnect.
            if (webSocket.resource() != null) {
                final Action action = ((AtmosphereResourceImpl) webSocket.resource()).action();
                if (action.timeout() != -1 && !framework.getAsyncSupport().getContainerName().contains("Netty")) {
                    final AtomicReference<Future<?>> f = new AtomicReference();
                    f.set(scheduler.scheduleAtFixedRate(new Runnable() {
                        @Override
                        public void run() {
                            if (WebSocket.class.isAssignableFrom(webSocket.getClass())
                                    && System.currentTimeMillis() - WebSocket.class.cast(webSocket).lastWriteTimeStampInMilliseconds() > action.timeout()) {
                                asynchronousProcessor.endRequest(((AtmosphereResourceImpl) webSocket.resource()), false);
                                f.get().cancel(true);
                            }
                        }
                    }, action.timeout(), action.timeout(), TimeUnit.MILLISECONDS));
                }
            } else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.