Example usage for java.util AbstractQueue clear

List of usage examples for java.util AbstractQueue clear

Introduction

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

Prototype

public void clear() 

Source Link

Document

Removes all of the elements from this queue.

Usage

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

/**
 * get???//from www.  j  a  va 2s  . 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");
}