/** Init calls the @OnInit methods. */ private void init(StubAmp stub) { // BuildMessageAmp buildMessage = new BuildMessageAmp(this); OnInitMessage onInitMsg = new OnInitMessage(this); _queue.offer(onInitMsg); _queue.wake(); }
private void start(StubAmp stub) { if (!_lifecycle.toStarting()) { return; } // OutboxAmpBase buildContext = new OutboxAmpBase(); // BuildMessageAmp buildMessage = new BuildMessageAmp(this); // MessageAmp oldMessage = ContextMessageAmp.getAndSet(buildMessage); // Outbox<MessageAmp> oldContext = OutboxThreadLocal.getCurrent(); try { // OutboxThreadLocal.setCurrent(buildContext); MessageAmp onActiveMsg = new OnActiveMessage(this, isSingle()); JournalAmp journal = stub.journal(); // buildContext.setMessage(onActiveMsg); if (journal != null) { if (log.isLoggable(Level.FINER)) { log.finer( L.l( "journal replay {0} ({1})", serviceRef().address(), serviceRef().api().getType())); } onActiveMsg = new OnActiveReplayMessage(this, stub, isSingle()); ActiveResult activeResult = new ActiveResult(onActiveMsg); ReplayMessage replayMsg = new ReplayMessage(this, _queue, activeResult); // buildContext.setMessage(replayMsg); _queue.offer(replayMsg); _queue.wake(); } else { // _worker.onActive(); // _queue.offer(onActiveMsg); _lifecycle.toActive(); // _queue.wake(); } } finally { // OutboxThreadLocal.setCurrent(oldContext); // ContextMessageAmp.set(oldMessage); } }
/** Closes the inbox */ @Override public void shutdown(ShutdownModeAmp mode) { if (!_lifecycle.toStopping()) { return; } _lifecycle.toDestroy(); OnShutdownMessage shutdownMessage = new OnShutdownMessage(this, mode, isSingle()); _queue.offer(shutdownMessage); // _queue.close(); /* for (Actor<?> actorProcessor : _queueActors) { actorProcessor.close(); } */ _queue.wakeAllAndWait(); shutdownMessage.waitFor(1, TimeUnit.SECONDS); super.shutdown(mode); try (OutboxAmp outbox = OutboxAmp.currentOrCreate(manager())) { Object ctx = outbox.getAndSetContext(this); try { outbox.flush(); if (!isSingle()) { _worker.shutdown(mode); } } finally { outbox.getAndSetContext(ctx); } } // XXX: _worker.shutdown(ShutdownModeAmp.IMMEDIATE); }
@Override public final void offerAndWake(MessageAmp message, long callerTimeout) { if (isClosed()) { // _lifecycle.isAfterStopping()) { message.fail( new ServiceExceptionClosed( L.l("Closed {0}, stub {1} for message {2}", serviceRef(), _stubMain, message))); return; } QueueDeliver<MessageAmp> queue = _queue; long timeout = Math.min(callerTimeout, _sendTimeout); if (!queue.offer(message, timeout, TimeUnit.MILLISECONDS)) { // ThreadDump.create().dumpThreads(); _fullHandler.onQueueFull(serviceRef(), queue.size(), timeout, TimeUnit.MILLISECONDS, message); } queue.wake(); }
@Override public boolean offerResult(MessageAmp message) { if (_lifecycle.isAfterStopping()) { message.fail( new ServiceExceptionClosed( L.l("closed {0} for message {1} and inbox {2}", serviceRef(), message, this))); return true; } QueueDeliver<MessageAmp> queue = _queue; boolean value = queue.offer(message, 0, TimeUnit.MILLISECONDS); // boolean value = queue.offer(message, 10, TimeUnit.MILLISECONDS, 0); // XXX: offer shouldn't automatically wake // queue.wake(); if (!value) { InboxQueueReplyOverflow overflowQueue; synchronized (this) { overflowQueue = _replyOverflowQueue; if (overflowQueue == null) { _replyOverflowQueue = overflowQueue = new InboxQueueReplyOverflow(queue); } } return overflowQueue.offer(message); } return value; // offerAndWake(message); // return true; }
@Override public boolean offer(MessageAmp message, long callerTimeout) { if (_lifecycle.isAfterStopping()) { message.fail( new ServiceExceptionClosed(L.l("closed {0} for message {1}", serviceRef(), message))); return true; } QueueDeliver<MessageAmp> queue = _queue; long timeout = Math.min(_sendTimeout, callerTimeout); boolean result = queue.offer(message, timeout, TimeUnit.MILLISECONDS); if (!result) { _fullHandler.onQueueFull(serviceRef(), queue.size(), timeout, TimeUnit.MILLISECONDS, message); return false; } return result; }