Package java.util.concurrent.atomic

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


            {
                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

    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

            // 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

    @Test
    public void testEncoder() throws IOException, ServletException, InterruptedException {

        AtmosphereRequest request = new AtmosphereRequest.Builder().pathInfo("/h").method("GET").build();
        AtmosphereResponse response = AtmosphereResponse.newInstance();
        final AtomicReference<String> ref = new AtomicReference();

        response.asyncIOWriter(new AsyncIOWriterAdapter() {
            @Override
            public AsyncIOWriter write(AtmosphereResponse r, byte[] data) throws IOException {
                ref.set(new String(data));
                return this;
            }
        });
        framework.doCometSupport(request, response);
        assertNotNull(r.get());
        latch.get().await(5, TimeUnit.SECONDS);
        r.get().resume();
        assertNotNull(message.get());
        assertEquals(message.get(), "message");
        assertEquals(ref.get(), "message-yo!");

    }
View Full Code Here

      }), taskOwner);
    }

    @SuppressWarnings("unchecked")
    @Test public void testIteratorRetainAcrossTransactions() throws Exception {
  final AtomicReference<Iterator<Object>> iterRef = new AtomicReference();
  txnScheduler.runTask(
      new TestTask(new TestAbstractKernelRunnable() {
    public void run() {
        set.add(one);
        Iterator<Object> iter = set.iterator();
        iterRef.set(iter);
        dataService.setBinding("iter",
             new ManagedSerializable(iter));
    }
      }), taskOwner);
  txnScheduler.runTask(
      new TestTask(new TestAbstractKernelRunnable() {
    public void run() {
        Iterator<Object> iter = iterRef.get();
        try {
      iter.hasNext();
      fail("Expected TransactionNotActiveException");
        } catch (TransactionNotActiveException e) {
        }
View Full Code Here

            throw new BindTransportException("Failed to resolve host [" + bindHost + "]", e);
        }
        final InetAddress hostAddress = hostAddressX;

        PortsRange portsRange = new PortsRange(port);
        final AtomicReference<Exception> lastException = new AtomicReference();
        boolean success = portsRange.iterate(new PortsRange.PortCallback() {
            @Override
            public boolean onPortNumber(int portNumber) {
                try {
                    serverChannel = serverBootstrap.bind(new InetSocketAddress(hostAddress, portNumber));
                } catch (Exception e) {
                    lastException.set(e);
                    return false;
                }
                return true;
            }
        });
        if (!success) {
            throw new BindTransportException("Failed to bind to [" + port + "]", lastException.get());
        }

        logger.debug("Bound to address [{}]", serverChannel.getLocalAddress());

        InetSocketAddress boundAddress = (InetSocketAddress) serverChannel.getLocalAddress();
View Full Code Here

                        + "is not on-site and not permitted by default. Check 'websocket.onsiteonly' setting in configuration.");
            }
        }

        PortsRange portsRange = new PortsRange(port);
        final AtomicReference<Exception> lastException = new AtomicReference();
        boolean success = portsRange.iterate(new PortsRange.PortCallback() {
            @Override
            public boolean onPortNumber(int portNumber) {
                try {
                    serverChannel = serverBootstrap.bind(new InetSocketAddress(hostAddress, portNumber));
                } catch (Exception e) {
                    lastException.set(e);
                    return false;
                }
                return true;
            }
        });
        if (!success) {
            throw new BindHttpException("Failed to bind to [" + port + "]", lastException.get());
        }
        InetSocketAddress boundAddress = (InetSocketAddress) serverChannel.getLocalAddress();
        InetSocketAddress publishAddress;
        try {
            publishAddress = new InetSocketAddress(networkService.resolvePublishHostAddress(publishHost), boundAddress.getPort());
View Full Code Here

    boolean alive() {
        return thread != null && thread.isAlive() && !data.queue.isShutdown();
    }
   
    static RubyThread createThread(final Ruby runtime, final FiberData data, final SizedQueue queue, final Block block) {
        final AtomicReference<RubyThread> fiberThread = new AtomicReference();
        runtime.getFiberExecutor().execute(new Runnable() {
            public void run() {
                ThreadContext context = runtime.getCurrentContext();
                context.setFiber(data.fiber.get());
                context.setRootThread(data.parent);
                fiberThread.set(context.getThread());
               
                IRubyObject init = data.queue.pop(context);

                try {
                    try {
                        IRubyObject result;

                        if (init == NEVER) {
                            result = block.yieldSpecific(context);
                        } else {
                            result = block.yieldArray(context, init, null);
                        }

                        data.prev.data.queue.push(context, new IRubyObject[] { result });
                    } finally {
                        data.queue.shutdown();
                        runtime.getThreadService().disposeCurrentThread();
                    }
                } catch (JumpException.FlowControlException fce) {
                    if (data.prev != null) {
                        data.prev.thread.raise(fce.buildException(runtime).getException());
                    }
                } catch (IRBreakJump bj) {
                    // This is one of the rare cases where IR flow-control jumps
                    // leaks into the runtime impl.
                    if (data.prev != null) {
                        data.prev.thread.raise(((RaiseException)IRException.BREAK_LocalJumpError.getException(runtime)).getException());
                    }
                } catch (IRReturnJump rj) {
                    // This is one of the rare cases where IR flow-control jumps
                    // leaks into the runtime impl.
                    if (data.prev != null) {
                        data.prev.thread.raise(((RaiseException)IRException.RETURN_LocalJumpError.getException(runtime)).getException());
                    }
                } catch (RaiseException re) {
                    if (data.prev != null) {
                        data.prev.thread.raise(re.getException());
                    }
                } catch (Throwable t) {
                    if (data.prev != null) {
                        data.prev.thread.raise(JavaUtil.convertJavaToUsableRubyObject(runtime, t));
                    }
                } finally {
                    // clear reference to the fiber's thread
                    ThreadFiber tf = data.fiber.get();
                    if (tf != null) tf.thread = null;
                }
            }
        });
       
        while (fiberThread.get() == null) {Thread.yield();}
       
        return fiberThread.get();
    }
View Full Code Here

    @SuppressWarnings("rawtypes")
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) 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

TOP

Related Classes of java.util.concurrent.atomic.AtomicReference

Copyright © 2018 www.massapicom. 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.