synchronized ibis.ipl.IbisIdentifier waitUntilTerminated() { while (!(terminated || stopped)) { try { wait(); } catch (final InterruptedException e) { // IGNORE } } return terminateEvent.getIbis(); }
void writeState(DataOutputStream out, int joinTime) throws IOException { ByteArrayOutputStream arrayOut = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(arrayOut); synchronized (this) { if (!initialized) { throw new IOException("state not initialized yet"); } dataOut.writeInt(time); members.writeTo(dataOut); elections.writeTo(dataOut); Event[] signals = eventList.getSignalEvents(joinTime, time); dataOut.writeInt(signals.length); for (Event event : signals) { event.writeTo(dataOut); } dataOut.writeBoolean(closed); if (closed) { closeEvent.writeTo(out); } dataOut.writeBoolean(terminated); if (terminated) { terminateEvent.writeTo(out); } } dataOut.flush(); dataOut.close(); byte[] bytes = arrayOut.toByteArray(); out.writeInt(bytes.length); out.write(bytes); logger.debug("pool state size = " + bytes.length); }
private synchronized void handleEvent(Event event) { logger.debug("handling event: " + event); switch (event.getType()) { case Event.JOIN: members.add(new Member(event.getIbis(), event)); if (statistics != null) { statistics.newPoolSize(members.size()); } break; case Event.LEAVE: members.remove(event.getIbis()); if (statistics != null) { statistics.newPoolSize(members.size()); } break; case Event.DIED: IbisIdentifier died = event.getIbis(); members.remove(died); if (statistics != null) { statistics.newPoolSize(members.size()); } if (died.equals(registry.getIbisIdentifier())) { logger.debug("we were declared dead"); stop(); } break; case Event.SIGNAL: // Not handled here break; case Event.ELECT: elections.put(new Election(event)); if (statistics != null) { statistics.electionEvent(); } break; case Event.UN_ELECT: elections.remove(event.getDescription()); if (statistics != null) { statistics.electionEvent(); } break; case Event.POOL_CLOSED: closed = true; closeEvent = event; break; case Event.POOL_TERMINATED: terminated = true; terminateEvent = event; break; default: logger.error("unknown event type: " + event.getType()); } // wake up threads waiting for events notifyAll(); if (logger.isDebugEnabled()) { logger.debug("member list now: " + members); } }