Example usage for java.util.concurrent ConcurrentLinkedQueue toArray

List of usage examples for java.util.concurrent ConcurrentLinkedQueue toArray

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentLinkedQueue toArray.

Prototype

@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) 

Source Link

Document

Returns an array containing all of the elements in this queue, in proper sequence; the runtime type of the returned array is that of the specified array.

Usage

From source file:ua.pp.serga.socketio.IOConnection.java

/**
 * Transport connected./*from www .  java  2 s .c  o m*/
 * 
 * {@link IOTransport} calls this when a connection is established.
 */
public void transportConnected() {
    setState(STATE_READY);
    if (reconnectTask != null) {
        reconnectTask.cancel();
        reconnectTask = null;
    }
    resetTimeout();
    synchronized (outputBuffer) {
        if (transport.canSendBulk()) {
            ConcurrentLinkedQueue<String> outputBuffer = this.outputBuffer;
            this.outputBuffer = new ConcurrentLinkedQueue<String>();
            try {
                // DEBUG
                String[] texts = outputBuffer.toArray(new String[outputBuffer.size()]);
                logger.info("Bulk start:");
                for (String text : texts) {
                    logger.info("> " + text);
                }
                logger.info("Bulk end");
                // DEBUG END
                transport.sendBulk(texts);
            } catch (IOException e) {
                this.outputBuffer = outputBuffer;
            }
        } else {
            String text;
            while ((text = outputBuffer.poll()) != null)
                sendPlain(text);
        }
        this.keepAliveInQueue = false;
    }
}

From source file:com.huobi.demo.socketio.core.IOConnection.java

/**
 * Transport connected./* w w w .j av  a 2s.  co m*/
 * 
 * {@link IOTransport} calls this when a connection is established.
 */
public synchronized void transportConnected() {
    setState(STATE_READY);
    if (reconnectTask != null) {
        reconnectTask.cancel();
        reconnectTask = null;
    }
    resetTimeout();
    if (transport.canSendBulk()) {
        ConcurrentLinkedQueue<String> outputBuffer = this.outputBuffer;
        this.outputBuffer = new ConcurrentLinkedQueue<String>();
        try {
            // DEBUG
            String[] texts = outputBuffer.toArray(new String[outputBuffer.size()]);
            logger.debug("Bulk start:");
            for (String text : texts) {
                logger.debug("> " + text);
            }
            logger.debug("Bulk end");
            // DEBUG END
            transport.sendBulk(texts);
        } catch (IOException e) {
            this.outputBuffer = outputBuffer;
        }
    } else {
        String text;
        while ((text = outputBuffer.poll()) != null)
            sendPlain(text);
    }
    this.keepAliveInQueue = false;
}

From source file:org.sunnycode.zkws.socketio.impl.IOConnection.java

/**
 * Transport connected./*from   ww  w.j  av  a 2  s.c  o m*/
 * 
 * {@link IOTransport} calls this when a connection is established.
 */
public synchronized void transportConnected() {
    setState(STATE_READY);
    if (reconnectTask != null) {
        reconnectTask.cancel();
        reconnectTask = null;
    }
    resetTimeout();
    if (transport.canSendBulk()) {
        ConcurrentLinkedQueue<String> outputBuffer = this.outputBuffer;
        this.outputBuffer = new ConcurrentLinkedQueue<String>();
        try {
            // DEBUG
            String[] texts = outputBuffer.toArray(new String[outputBuffer.size()]);
            logger.info("Bulk start:");
            for (String text : texts) {
                logger.info("> " + text);
            }
            logger.info("Bulk end");
            // DEBUG END
            transport.sendBulk(texts);
        } catch (IOException e) {
            this.outputBuffer = outputBuffer;
        }
    } else {
        String text;
        while ((text = outputBuffer.poll()) != null)
            sendPlain(text);
    }
    this.keepAliveInQueue = false;
}

From source file:com.xeiam.xchange.streaming.socketio.IOConnection.java

/**
 * Transport connected. {@link IOTransport} calls this when a connection is established.
 *//*from ww w.j a  va2s .  c  om*/
public void transportConnected() {

    setState(STATE_READY);
    if (reconnectTask != null) {
        reconnectTask.cancel();
        reconnectTask = null;
    }
    resetTimeout();
    synchronized (outputBuffer) {
        if (transport.canSendBulk()) {
            ConcurrentLinkedQueue<String> outputBuffer = this.outputBuffer;
            this.outputBuffer = new ConcurrentLinkedQueue<String>();
            try {
                // DEBUG
                String[] texts = outputBuffer.toArray(new String[outputBuffer.size()]);
                log.debug("Bulk start:");
                for (String text : texts) {
                    log.debug("> " + text);
                }
                log.debug("Bulk end");
                // DEBUG END
                transport.sendBulk(texts);
            } catch (IOException e) {
                this.outputBuffer = outputBuffer;
            }
        } else {
            String text;
            while ((text = outputBuffer.poll()) != null) {
                sendPlain(text);
            }
        }
        this.keepAliveInQueue = false;
    }
}

From source file:de.mmbbs.io.socket.IOConnection.java

/**
 * Transport connected.//from   www .ja va2s  .  c o m
 * 
 * {@link IOTransport} calls this when a connection is established.
 */
public synchronized void transportConnected() {
    setState(STATE_READY);
    if (reconnectTask != null) {
        reconnectTask.cancel();
        reconnectTask = null;
    }
    if (heartBeatTask != null) {
        heartBeatTask.cancel();
    }
    heartBeatTask = new HeartBeatTask(); // heartbeat loop
    backgroundTimer.schedule(heartBeatTask, heartbeatTimeout, heartbeatTimeout);
    resetTimeout();
    if (transport.canSendBulk()) {
        ConcurrentLinkedQueue<String> outputBuffer = this.outputBuffer;
        this.outputBuffer = new ConcurrentLinkedQueue<String>();
        try {
            // DEBUG
            String[] texts = outputBuffer.toArray(new String[outputBuffer.size()]);
            logger.info("Bulk start:");
            for (String text : texts) {
                logger.info("> " + text);
            }
            logger.info("Bulk end");
            // DEBUG END
            transport.sendBulk(texts);
        } catch (IOException e) {
            this.outputBuffer = outputBuffer;
        }
    } else {
        String text;
        while ((text = outputBuffer.poll()) != null)
            sendPlain(text);
    }
    this.keepAliveInQueue = false;
}