public StaleMessageDepot(String depotName) { this.messageDepot = new PersistentQueue<String>(depotName, String.class); }
public void clear() { messages.clear(); msgMapping.clear(); }
/** * * @param messageId * @return false if message arrived before. true */ public synchronized boolean putStableMessage(String messageId) { if (StringUtil.isEmpty(messageId)) { return true; } boolean isContains = messageDepot.contains(messageId); if (!isContains) { messageDepot.offer(messageId); while (messageDepot.size() > MAXLENGTH) { messageDepot.poll(); } } return !isContains; } }
@Override public boolean remove(Object object) { boolean result = messages.remove(object); this.storeMessageQueue(); return result; }
E poll(String msgId) { if (!StringUtil.isEmpty(msgId) && msgMapping.containsKey(msgId)) { E returnValue = msgMapping.remove(msgId); messages.remove(returnValue); return returnValue; } return this.poll(); }
public boolean isEmpty() { return operationQueue.isEmpty(); } }
void offer(E msg) { if (!StringUtil.isEmpty(msg.getId())) { msgMapping.put(msg.getId(), msg); } messages.offer(msg); }
public Operation poll() { return operationQueue.poll(); }
public PersistentQueue(String peerId, Class<E> clazz) { messages = new ConcurrentLinkedQueue<>(); this.type = clazz; queueKey = QUEUE_KEY + "." + peerId; LinkedList<E> storedMessages = restoreMessageQueue(); if (null != storedMessages && !storedMessages.isEmpty()) { messages.addAll(storedMessages); } }
@Override public boolean addAll(Collection<? extends E> collection) { boolean result = messages.addAll(collection); this.storeMessageQueue(); return result; }
public Operation poll(int requestId) { if (requestId != CommandPacket.UNSUPPORTED_OPERATION && cache.get(requestId) != null) { Operation returnValue = cache.get(requestId); cache.remove(requestId); operationQueue.remove(returnValue); Runnable timeoutTask = timeoutCache.get(requestId); timeoutCache.remove(requestId); if (timeoutTask != null) { BackgroundThreadpool.getInstance().removeScheduledTask(timeoutTask); } return returnValue; } return this.poll(); }
public boolean isEmpty() { return messages.isEmpty(); } }
public void offer(final Operation op) { if (op.requestId != CommandPacket.UNSUPPORTED_OPERATION) { cache.put(op.requestId, op); Runnable timeoutTask = new Runnable() { @Override public void run() { Operation polledOP = poll(op.requestId); if (polledOP != null) { Conversation.AVIMOperation operation = Conversation.AVIMOperation.getAVIMOperation(polledOP.operation); InternalConfiguration.getOperationTube().onOperationCompleted(polledOP.sessionId, polledOP.conversationId, polledOP.requestId, operation, new AVException(AVException.TIMEOUT, "Timeout Exception")); } } }; timeoutCache.put(op.requestId, timeoutTask); BackgroundThreadpool.getInstance().executeDelayed(timeoutTask, AVIMOptions.getGlobalOptions().getTimeoutInSecs()); } operationQueue.offer(op); }
E poll() { return messages.poll(); }
@Override public void clear() { messages.clear(); this.storeMessageQueue(); }
public AVIMOperationQueue(String key) { operationQueue = new PersistentQueue<Operation>("operation.queue." + key, Operation.class); setupCache(); }
public void clear() { operationQueue.clear(); cache.clear(); }
@Override public boolean add(E e) { boolean result = messages.add(e); this.storeMessageQueue(); return result; }
PendingMessageCache(String peerId, Class<E> type) { this.messages = new PersistentQueue<E>(peerId, type); this.setupMapping(); }
@Override public boolean offer(E e) { boolean result = messages.offer(e); this.storeMessageQueue(); return result; }