Package java.util.concurrent.atomic

Examples of java.util.concurrent.atomic.AtomicBoolean


       
        while (reqHdl.getLastExchange() == null) {
            QAUtil.sleep(100);
        }
       
        final AtomicBoolean isAllDataSend = new AtomicBoolean();
        final IHttpExchange serverExchange = reqHdl.getLastExchange();
       
        System.out.println("[" + (System.currentTimeMillis() - startTime) + "] server: suspend receiving");
        serverExchange.getConnection().suspendReceiving();
        Runnable resumeTask = new Runnable() {
           
            public void run() {
               
                QAUtil.sleep(1500);
                if (isAllDataSend.get()) {
                    isErrorOccured.set(true);
                }
                try {
                    System.out.println("[" + (System.currentTimeMillis() - startTime) + "]  server: resume receving");
                    serverExchange.getConnection().resumeReceiving();
                } catch(IOException ioe) {
                    throw new RuntimeException(ioe);
                }
            }
        };
        new Thread(resumeTask).start();
       
        System.out.println("[" + (System.currentTimeMillis() - startTime) + "]  client: start sending...");
        for (int i = 0; i < 100; i++) {
            dataSink.write(QAUtil.generateByteArray(1000));
        }
        isAllDataSend.set(true);
       
        System.out.println("[" + (System.currentTimeMillis() - startTime) + "]  client: finished sending");
       
        QAUtil.sleep(2500);
       
View Full Code Here


   
    while (reqHdl.getLastExchange() == null) {
        QAUtil.sleep(100);
    }
   
    final AtomicBoolean isAllDataSend = new AtomicBoolean();
    final IHttpExchange serverExchange = reqHdl.getLastExchange();
   
    System.out.println("[" + (System.currentTimeMillis() - startTime) + "] server: suspend receiving");
    serverExchange.getConnection().suspendReceiving();
    Runnable resumeTask = new Runnable() {
       
        public void run() {
           
            QAUtil.sleep(1500);
            if (isAllDataSend.get()) {
                isErrorOccured.set(true);
            }
            try {
                System.out.println("[" + (System.currentTimeMillis() - startTime) + "]  server: resume receving");
                serverExchange.getConnection().resumeReceiving();
            } catch(IOException ioe) {
                throw new RuntimeException(ioe);
            }
        }
    };
    new Thread(resumeTask).start();
   
    System.out.println("[" + (System.currentTimeMillis() - startTime) + "]  client: start sending...");
    for (int i = 0; i < 100; i++) {
        dataSink.write(QAUtil.generateByteArray(1000));
    }
    isAllDataSend.set(true);
   
    System.out.println("[" + (System.currentTimeMillis() - startTime) + "]  client: finished sending");
   
    QAUtil.sleep(2500);
   
View Full Code Here

       
        while (reqHdl.getLastExchange() == null) {
            QAUtil.sleep(100);
        }
       
        final AtomicBoolean isAllDataSend = new AtomicBoolean();
        final IHttpExchange serverExchange = reqHdl.getLastExchange();
       
        System.out.println("[" + (System.currentTimeMillis() - startTime) + "] server: suspend receiving");
        serverExchange.getConnection().suspendReceiving();
        Runnable resumeTask = new Runnable() {
           
            public void run() {
               
                QAUtil.sleep(1500);
                if (isAllDataSend.get()) {
                    isErrorOccured.set(true);
                }
                try {
                    System.out.println("[" + (System.currentTimeMillis() - startTime) + "]  server: resume receving");
                    serverExchange.getConnection().resumeReceiving();
                } catch(IOException ioe) {
                    throw new RuntimeException(ioe);
                }
            }
        };
        new Thread(resumeTask).start();
       
        System.out.println("[" + (System.currentTimeMillis() - startTime) + "]  client: start sending...");
        for (int i = 0; i < 100; i++) {
            dataSink.write(QAUtil.generateByteArray(1000));
        }
        isAllDataSend.set(true);
       
        System.out.println("[" + (System.currentTimeMillis() - startTime) + "]  client: finished sending");
       
        QAUtil.sleep(2500);
       
View Full Code Here

   
    while (reqHdl.getLastExchange() == null) {
        QAUtil.sleep(100);
    }
   
    final AtomicBoolean isAllDataSend = new AtomicBoolean();
    final IHttpExchange serverExchange = reqHdl.getLastExchange();
   
    System.out.println("[" + (System.currentTimeMillis() - startTime) + "] server: suspend receiving");
    serverExchange.getConnection().suspendReceiving();
    Runnable resumeTask = new Runnable() {
       
        public void run() {
           
            QAUtil.sleep(1500);
            if (isAllDataSend.get()) {
                isErrorOccured.set(true);
            }
            try {
                System.out.println("[" + (System.currentTimeMillis() - startTime) + "]  server: resume receving");
                serverExchange.getConnection().resumeReceiving();
            } catch(IOException ioe) {
                throw new RuntimeException(ioe);
            }
        }
    };
    new Thread(resumeTask).start();
   
    System.out.println("[" + (System.currentTimeMillis() - startTime) + "]  client: start sending...");
    for (int i = 0; i < 100; i++) {
        dataSink.write(QAUtil.generateByteArray(1000));
    }
    isAllDataSend.set(true);
   
    System.out.println("[" + (System.currentTimeMillis() - startTime) + "]  client: finished sending");
   
    QAUtil.sleep(2500);
   
View Full Code Here

        
         while (reqHdl.getLastExchange() == null) {
             QAUtil.sleep(100);
         }
        
         final AtomicBoolean isAllDataSend = new AtomicBoolean();
         final IHttpExchange serverExchange = reqHdl.getLastExchange();
        
         System.out.println("[" + (System.currentTimeMillis() - startTime) + "] server: suspend receiving");
         serverExchange.getConnection().suspendReceiving();
         Runnable resumeTask = new Runnable() {
            
             public void run() {
                
                 QAUtil.sleep(1500);
                 if (isAllDataSend.get()) {
                     isErrorOccured.set(true);
                 }
                 try {
                     System.out.println("[" + (System.currentTimeMillis() - startTime) + "]  server: resume receving");
                     serverExchange.getConnection().resumeReceiving();
                 } catch(IOException ioe) {
                     throw new RuntimeException(ioe);
                 }
             }
         };
         new Thread(resumeTask).start();
        
         System.out.println("[" + (System.currentTimeMillis() - startTime) + "]  client: start sending...");
         for (int i = 0; i < 100; i++) {
             dataSink.write(QAUtil.generateByteArray(1000));
         }
         isAllDataSend.set(true);
        
         System.out.println("[" + (System.currentTimeMillis() - startTime) + "]  client: finished sending");
        
         QAUtil.sleep(2500);
        
View Full Code Here

     * @throws SocketTimeoutException  is the max wait time is reached
     * @throws IOException
     */
    public static void waitUntilComplete(final IHttpMessage message, int timeoutMillis) throws SocketTimeoutException, IOException {
       
        final AtomicBoolean isComplete = new AtomicBoolean(false);
       
        if (message.hasBody()) {
           
            if (message.getNonBlockingBody().isComplete()) {
                return;
               
            } else {
                long start = System.currentTimeMillis();

                IBodyCompleteListener cl = new IBodyCompleteListener() {
   
                    public void onComplete() throws IOException {
                        synchronized (message) {
                            isComplete.set(true);
                            message.notifyAll();
                        }
                    }
                };
                message.getNonBlockingBody().addCompleteListener(cl);
               

                do {
                    synchronized (message) {
                        if (!isComplete.get()) {
                            try {
                                message.wait(timeoutMillis);
                            } catch (InterruptedException ignore) { }
                           
                            if ((start - System.currentTimeMillis()) > timeoutMillis) {
                                throw new SocketTimeoutException("timeout " + DataConverter.toFormatedDuration(timeoutMillis) + " reached");
                            }
                        }
                    }
                   
                } while (!isComplete.get());
            }
            
        } else {
            return;
        }
View Full Code Here

     * @throws SocketTimeoutException  is the max wait time is reached
     * @throws IOException
     */
    public static void waitUntilComplete(final IHttpMessage message, int timeoutMillis) throws SocketTimeoutException, IOException {
       
        final AtomicBoolean isComplete = new AtomicBoolean(false);
       
        if (message.hasBody()) {
           
            if (message.getNonBlockingBody().isComplete()) {
                return;
               
            } else {
                long start = System.currentTimeMillis();

                IBodyCompleteListener cl = new IBodyCompleteListener() {
   
                    public void onComplete() throws IOException {
                        synchronized (message) {
                            isComplete.set(true);
                            message.notifyAll();
                        }
                    }
                };
                message.getNonBlockingBody().addCompleteListener(cl);
               

                do {
                    synchronized (message) {
                        if (!isComplete.get()) {
                            try {
                                message.wait(timeoutMillis);
                            } catch (InterruptedException ignore) { }
                           
                            if ((start - System.currentTimeMillis()) > timeoutMillis) {
                                throw new SocketTimeoutException("timeout " + DataConverter.toFormatedDuration(timeoutMillis) + " reached");
                            }
                        }
                    }
                   
                } while (!isComplete.get());
            }
            
        } else {
            return;
        }
View Full Code Here

    this(MAX_CONNECTION_PER_HOST);
  }
 
  protected AbstractConnectionManager(int maxConnectionPerHost) {
    this.maxConnectionsPerHost = maxConnectionPerHost;
    shutdown = new AtomicBoolean(false);
    used = new ConcurrentHashMap<Host, Semaphore>();
  }
View Full Code Here

        final CountDownLatch latch = new CountDownLatch(2);
        final CountDownLatch suspended = new CountDownLatch(1);
        atmoServlet.addAtmosphereHandler(ROOT, new AbstractHttpAtmosphereHandler() {

            AtomicBoolean b = new AtomicBoolean(false);
            AtmosphereResource<HttpServletRequest, HttpServletResponse> suspendedEvent;

            public void onRequest(AtmosphereResource<HttpServletRequest, HttpServletResponse> event) throws IOException {
                if (!b.getAndSet(true)) {
                    try {
                        suspendedEvent = event;
                        event.suspend();
                    } finally {
                        suspended.countDown();
View Full Code Here

        final CountDownLatch latch = new CountDownLatch(2);
        final CountDownLatch suspended = new CountDownLatch(1);
        atmoServlet.addAtmosphereHandler(ROOT, new AbstractHttpAtmosphereHandler() {

            AtomicBoolean b = new AtomicBoolean(false);

            public void onRequest(AtmosphereResource<HttpServletRequest, HttpServletResponse> event) throws IOException {
                if (!b.getAndSet(true)) {
                    try {
                        event.suspend();
                    } finally {
                        suspended.countDown();
                    }
View Full Code Here

TOP

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

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.