Example usage for java.util AbstractQueue size

List of usage examples for java.util AbstractQueue size

Introduction

In this page you can find the example usage for java.util AbstractQueue size.

Prototype

int size();

Source Link

Document

Returns the number of elements in this collection.

Usage

From source file:com.google.code.fqueue.memcached.storage.FSStorage.java

/**
 * get???/*w ww .j a v a2s . c  o m*/
 * 
 * @param keystring
 * @return
 * @throws ClientException
 */
private LocalCacheElement getProtocol(String keystring) throws ClientException {
    // ?
    if (keystring.startsWith("size")) {
        try {
            // size|bbs
            // size?????????
            String[] clientInfo = QueueClient.parse(keystring, '|');
            if (clientInfo.length < 2 || authorizationMap.containsKey(clientInfo[1]) == false) {
                return null;
            }
            AbstractQueue<byte[]> sizeQueue = getClientQueue(clientInfo[1]);
            if (sizeQueue == null) {
                return null;
            }
            int size = sizeQueue.size();
            LocalCacheElement element = new LocalCacheElement(keystring, 0, 0, 0);
            element.setData(String.valueOf(size).getBytes());
            return element;
        } catch (Exception e) {
            log.error("getsize " + keystring + "error", e);
            return null;
        }
    }
    // 
    if (keystring.startsWith("clear")) {
        try {
            // clear|bbs|pass
            String[] clientInfo = QueueClient.parse(keystring, '|');
            if (clientInfo.length < 3 || valid(clientInfo[1], clientInfo[2]) == false) {
                throw new ClientException("Authorization error");
            }
            AbstractQueue<byte[]> queue = getClientQueue(clientInfo[1]);
            queue.clear();
            LocalCacheElement element = new LocalCacheElement(keystring, 0, 0, 0);
            element.setData(String.valueOf(queue.size()).getBytes());
            return element;
        } catch (Exception e) {
            log.error("getsize " + keystring + "error", e);
            return null;
        }
    }
    // ????
    if (keystring.startsWith("reload")) {
        try {
            // reload|bbs|pass
            String[] clientInfo = QueueClient.parse(keystring, '|');
            if (clientInfo.length < 3 || valid(clientInfo[1], clientInfo[2]) == false) {
                throw new ClientException("Authorization error");
            }
            reloadAuthorization();
            LocalCacheElement element = new LocalCacheElement(keystring, 0, 0, 0);
            element.setData("reloadAuthorization".getBytes());
            return element;
        } catch (ConfigException e) {
            log.error(e.getMessage(), e);
        } catch (Exception e) {
            log.error("reloadAuthorization error", e);
            return null;
        }
    }
    // ????
    if (keystring.startsWith("monitor")) {
        try {
            // size|bbs
            // size?????????
            String[] clientInfo = QueueClient.parse(keystring, '|');
            if (clientInfo.length < 2) {
                return null;
            }
            String items = clientInfo[1];
            StringBuilder stats = new StringBuilder();
            if (items != null) {
                String[] itemList = StringUtils.split(items, ",");
                for (int i = 0, len = itemList.length; i < len; i++) {
                    if (i > 0) {
                        stats.append("\r\n");
                    }
                    String data = JVMMonitor.getMonitorStats(itemList[i]);
                    stats.append(data);
                }
            } else {
                stats.append("need items");
            }

            LocalCacheElement element = new LocalCacheElement(keystring, 0, 0, 0);
            element.setData(stats.toString().getBytes());
            return element;
        } catch (Exception e) {
            log.error("monitor " + keystring + "error", e);
            return null;
        }
    }
    throw new ClientException(keystring + " command Unsupported now");
}