Example usage for java.io ObjectOutputStream flush

List of usage examples for java.io ObjectOutputStream flush

Introduction

In this page you can find the example usage for java.io ObjectOutputStream flush.

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes the stream.

Usage

From source file:org.xwoot.jxta.JxtaPeer.java

/** {@inheritDoc} **/
public Object sendObject(Object object, PipeAdvertisement pipeAdv) throws JxtaException {
    if (!this.isConnectedToGroup()) {
        throw new PeerGroupException("The peer has not yet joined a group and contacted a RDV peer.");
    }//from  w w w .  java  2s.  c  o m

    if (!(object instanceof Serializable)) {
        throw new IllegalArgumentException(
                "The object does not implement the interface java.io.Serializable and can not be sent.");
    }

    boolean failed = false;

    Socket socket = null;

    InputStream is = null;
    OutputStream os = null;
    ObjectInputStream ois = null;
    ObjectOutputStream oos = null;
    try {
        socket = new JxtaSocket(this.currentJoinedGroup, pipeAdv);
        socket.setSoTimeout(WAIT_INTERVAL_FOR_DIRECT_COMMUNICATION_CONNECTIONS);
    } catch (Exception e) {
        throw new JxtaException("Failed to create a direct connection using the provided pipe advertisement.",
                e);
    }

    try {
        os = socket.getOutputStream();
        oos = new ObjectOutputStream(os);

        oos.writeObject(object);

        oos.flush();
        os.flush();
    } catch (Exception e) {
        failed = true;
        throw new JxtaException(
                "Failed to send an object through a direct connection using the provided pipe advertisement.",
                e);
    } finally {
        try {
            if (oos != null) {
                oos.close();
            }
            if (os != null) {
                os.close();
            }

            // Close the socket only if this step has failed.
            if (failed && socket != null) {
                socket.close();
            }
        } catch (Exception e) {
            // Just log it.
            this.logger.warn("Failed to close streams for this conenction.");
        }
    }

    Object replyMessage = null;
    try {
        is = socket.getInputStream();
        ois = new ObjectInputStream(is);

        replyMessage = ois.readObject();

    } catch (EOFException eof) {
        this.logger.debug("There is no reply to this message. Returning null.");
        replyMessage = null;
    } catch (Exception e) {
        throw new JxtaException("Failed to receive reply message.", e);
    } finally {
        try {
            if (ois != null) {
                ois.close();
            }
        } catch (Exception e) {
            // Just log it.
            this.logger.warn("Failed to close object input stream for this conenction.", e);
        }

        try {
            if (is != null) {
                is.close();
            }
        } catch (Exception e) {
            // Just log it.
            this.logger.warn("Failed to close input stream for this conenction.", e);
        }

        try {
            // Close the socket, we are done.
            if (socket != null) {
                socket.close();
            }
        } catch (Exception e) {
            // Just log it.
            this.logger.warn("Failed to close socket for this conenction.");
        }
    }

    return replyMessage;
}

From source file:bftsmart.tom.core.TOMLayer.java

private void catch_up(int regency) {

    Logger.println("(TOMLayer.catch_up) verify STOPDATA info");
    ObjectOutputStream out = null;
    ByteArrayOutputStream bos = null;

    LastEidData lastHighestEid = lcManager.getHighestLastEid(regency);

    int currentEid = lastHighestEid.getEid() + 1;
    HashSet<SignedObject> signedCollects = null;
    byte[] propose = null;
    int batchSize = -1;

    // normalize the collects and apply to them the predicate "sound"
    if (lcManager.sound(lcManager.selectCollects(regency, currentEid))) {

        Logger.println("(TOMLayer.catch_up) sound predicate is true");

        signedCollects = lcManager.getCollects(regency); // all original collects that the replica has received

        Consensus cons = new Consensus(-1); // the only purpose of this object is to obtain the batchsize,
        // using code inside of createPropose()

        propose = createPropose(cons);/*from  w w  w.  ja  va 2s  . c  o  m*/
        batchSize = cons.batchSize;

        try { // serialization of the CATCH-UP message
            bos = new ByteArrayOutputStream();
            out = new ObjectOutputStream(bos);

            out.writeObject(lastHighestEid);

            //TODO: Missing: serialization of the proof

            out.writeInt(currentEid);
            out.writeObject(signedCollects);
            out.writeObject(propose);
            out.writeInt(batchSize);

            out.flush();
            bos.flush();

            byte[] payload = bos.toByteArray();
            out.close();
            bos.close();

            Logger.println("(TOMLayer.catch_up) sending SYNC message for regency " + regency);

            // send the CATCH-UP message
            communication.send(this.controller.getCurrentViewOtherAcceptors(), new LCMessage(
                    this.controller.getStaticConf().getProcessId(), TOMUtil.SYNC, regency, payload));

            finalise(regency, lastHighestEid, currentEid, signedCollects, propose, batchSize, true);

        } catch (IOException ex) {
            ex.printStackTrace();
            java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                out.close();
                bos.close();
            } catch (IOException ex) {
                ex.printStackTrace();
                java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

From source file:bftsmart.tom.core.Synchronizer.java

private void catch_up(int regency) {

    Logger.println("(Synchronizer.catch_up) verify STOPDATA info");
    ObjectOutputStream out = null;
    ByteArrayOutputStream bos = null;

    CertifiedDecision lastHighestCID = lcManager.getHighestLastCID(regency);

    int currentCID = lastHighestCID.getCID() + 1;
    HashSet<SignedObject> signedCollects = null;
    byte[] propose = null;
    int batchSize = -1;

    // normalize the collects and apply to them the predicate "sound"
    if (lcManager.sound(lcManager.selectCollects(regency, currentCID))) {

        Logger.println("(Synchronizer.catch_up) sound predicate is true");

        signedCollects = lcManager.getCollects(regency); // all original collects that the replica has received

        Decision dec = new Decision(-1); // the only purpose of this object is to obtain the batchsize,
                                         // using code inside of createPropose()

        propose = tom.createPropose(dec);
        batchSize = dec.batchSize;/*from  www . j a  v a2 s.  c o m*/

        try { // serialization of the CATCH-UP message
            bos = new ByteArrayOutputStream();
            out = new ObjectOutputStream(bos);

            out.writeObject(lastHighestCID);

            //TODO: Missing: serialization of the proof?
            out.writeObject(signedCollects);
            out.writeObject(propose);
            out.writeInt(batchSize);

            out.flush();
            bos.flush();

            byte[] payload = bos.toByteArray();
            out.close();
            bos.close();

            System.out.println("(Synchronizer.catch_up) sending SYNC message for regency " + regency);

            // send the CATCH-UP message
            communication.send(this.controller.getCurrentViewOtherAcceptors(), new LCMessage(
                    this.controller.getStaticConf().getProcessId(), TOMUtil.SYNC, regency, payload));

            finalise(regency, lastHighestCID, signedCollects, propose, batchSize, true);

        } catch (IOException ex) {
            ex.printStackTrace();
            java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                out.close();
                bos.close();
            } catch (IOException ex) {
                ex.printStackTrace();
                java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

From source file:bftsmart.tom.core.TOMLayer.java

/**
 * This method is called when there is a timeout and the request has already been forwarded to the leader
 * @param requestList List of requests that the replica wanted to order but didn't manage to
 *//*from w  ww  .ja va  2s  .c  o  m*/
public void triggerTimeout(List<TOMMessage> requestList) {

    ObjectOutputStream out = null;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    requestsTimer.stopTimer();
    requestsTimer.Enabled(false);

    // still not in the leader change phase?

    if (lcManager.getNextReg() == lcManager.getLastReg()) {

        Logger.println("(TOMLayer.triggerTimeout) initialize synch phase");

        lcManager.setNextReg(lcManager.getLastReg() + 1); // define next timestamp

        int regency = lcManager.getNextReg();

        // store messages to be ordered
        lcManager.setCurrentRequestTimedOut(requestList);

        // store information about messages that I'm going to send
        lcManager.addStop(regency, this.controller.getStaticConf().getProcessId());

        execManager.stop(); // stop consensus execution

        try { // serialize content to send in STOP message
            out = new ObjectOutputStream(bos);

            if (lcManager.getCurrentRequestTimedOut() != null) {

                //TODO: If this is null, then there was no timeout. What to do?
                byte[] msgs = bb.makeBatch(lcManager.getCurrentRequestTimedOut(), 0, 0, controller);
                out.writeBoolean(true);
                out.writeObject(msgs);
            } else {
                out.writeBoolean(false);
            }

            byte[] payload = bos.toByteArray();

            out.flush();
            bos.flush();

            out.close();
            bos.close();

            // send STOP-message
            Logger.println("(TOMLayer.triggerTimeout) sending STOP message to install regency " + regency);
            communication.send(this.controller.getCurrentViewOtherAcceptors(), new LCMessage(
                    this.controller.getStaticConf().getProcessId(), TOMUtil.STOP, regency, payload));

        } catch (IOException ex) {
            ex.printStackTrace();
            java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                out.close();
                bos.close();
            } catch (IOException ex) {
                ex.printStackTrace();
                java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        evaluateStops(regency); // evaluate STOP messages

    }

}

From source file:net.sf.farrago.server.FarragoServletCommandSink.java

private void handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
        throws ServletException {
    ObjectInputStream ois = null;
    ObjectOutputStream oos = null;

    try {//from  w w  w.  j a  v  a  2 s .c  o  m
        // Get the method to execute
        String method = httpServletRequest.getHeader(ServletCommandSinkIdentifier.METHOD_IDENTIFIER);

        if (method != null) {
            ois = new ObjectInputStream(httpServletRequest.getInputStream());
            // And initialize the output
            OutputStream os = httpServletResponse.getOutputStream();
            oos = new ObjectOutputStream(os);
            Object objectToReturn = null;

            try {
                // Some command to process ?
                if (method.equals(ServletCommandSinkIdentifier.PROCESS_COMMAND)) {
                    // Read parameter objects
                    Long connuid = (Long) ois.readObject();
                    Long uid = (Long) ois.readObject();
                    Command cmd = (Command) ois.readObject();
                    CallingContext ctx = (CallingContext) ois.readObject();
                    // Delegate execution to the CommandProcessor
                    objectToReturn = processor.process(connuid, uid, cmd, ctx);
                } else if (method.equals(ServletCommandSinkIdentifier.CONNECT_COMMAND)) {
                    String url = ois.readUTF();
                    Properties props = (Properties) ois.readObject();
                    Properties clientInfo = (Properties) ois.readObject();
                    CallingContext ctx = (CallingContext) ois.readObject();

                    ConnectionConfiguration connectionConfiguration = VJdbcConfiguration.singleton()
                            .getConnection(url);

                    if (connectionConfiguration != null) {
                        Connection conn = connectionConfiguration.create(props);
                        objectToReturn = processor.registerConnection(conn, connectionConfiguration, clientInfo,
                                ctx);
                    } else {
                        objectToReturn = new SQLException("VJDBC-Connection " + url + " not found");
                    }
                }
            } catch (Throwable t) {
                // Wrap any exception so that it can be transported back to
                // the client
                objectToReturn = SQLExceptionHelper.wrap(t);
            }

            // Write the result in the response buffer
            oos.writeObject(objectToReturn);
            oos.flush();

            httpServletResponse.flushBuffer();
        } else {
            // No VJDBC-Method ? Then we redirect the stupid browser user to
            // some information page :-)
            httpServletResponse.sendRedirect("index.html");
        }
    } catch (Exception e) {
        logger.error("Unexpected Exception", e);
        throw new ServletException(e);
    } finally {
        StreamCloser.close(ois);
        StreamCloser.close(oos);
    }
}

From source file:bftsmart.tom.core.TOMLayer.java

private void evaluateStops(int nextReg) {

    boolean enterFirstPhase = this.controller.getStaticConf().isBFT();
    boolean condition = false;
    ObjectOutputStream out = null;
    ByteArrayOutputStream bos = null;

    // pass to the leader change phase if more than f messages have been received already
    if (enterFirstPhase && lcManager.getStopsSize(nextReg) > this.controller.getQuorumF()
            && lcManager.getNextReg() == lcManager.getLastReg()) {

        Logger.println("(TOMLayer.evaluateStops) initialize synch phase");
        requestsTimer.Enabled(false);//  w  ww.  j a  v a 2 s  .co  m
        requestsTimer.stopTimer();

        lcManager.setNextReg(lcManager.getLastReg() + 1); // define next timestamp

        int regency = lcManager.getNextReg();

        // store information about message I am going to send
        lcManager.addStop(regency, this.controller.getStaticConf().getProcessId());

        execManager.stop(); // stop execution of consensus

        try { // serialize conent to send in the STOP message
            bos = new ByteArrayOutputStream();
            out = new ObjectOutputStream(bos);

            if (lcManager.getCurrentRequestTimedOut() != null) {

                //TODO: If this is null, there was no timeout. What shall be done then?
                out.writeBoolean(true);
                byte[] msgs = bb.makeBatch(lcManager.getCurrentRequestTimedOut(), 0, 0, controller);
                out.writeObject(msgs);
            } else {
                out.writeBoolean(false);
            }

            out.flush();
            bos.flush();

            byte[] payload = bos.toByteArray();
            out.close();
            bos.close();

            // send message STOP
            Logger.println("(TOMLayer.evaluateStops) sending STOP message to install regency " + regency);
            communication.send(this.controller.getCurrentViewOtherAcceptors(), new LCMessage(
                    this.controller.getStaticConf().getProcessId(), TOMUtil.STOP, regency, payload));

        } catch (IOException ex) {
            ex.printStackTrace();
            java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                out.close();
                bos.close();
            } catch (IOException ex) {
                ex.printStackTrace();
                java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    if (this.controller.getStaticConf().isBFT()) {
        condition = lcManager.getStopsSize(nextReg) > this.controller.getCertificateQuorum()
                && lcManager.getNextReg() > lcManager.getLastReg();
    } else {
        condition = (lcManager.getStopsSize(nextReg) > this.controller.getQuorumAccept()
                && lcManager.getNextReg() > lcManager.getLastReg());
    }
    // May I proceed to the synchronization phase?
    //if (lcManager.getStopsSize(nextReg) > this.reconfManager.getQuorum2F() && lcManager.getNextReg() > lcManager.getLastReg()) {
    if (condition) {

        Logger.println("(TOMLayer.evaluateStops) installing regency " + lcManager.getNextReg());
        lcManager.setLastReg(lcManager.getNextReg()); // define last timestamp

        int regency = lcManager.getLastReg();

        // avoid a memory leak
        lcManager.removeStops(nextReg);

        requestsTimer.Enabled(true);
        requestsTimer.setShortTimeout(-1);
        //requestsTimer.setTimeout(requestsTimer.getTimeout() * 2);
        requestsTimer.startTimer();

        //int leader = regency % this.reconfManager.getCurrentViewN(); // new leader
        int leader = lcManager.getNewLeader();
        int in = getInExec(); // eid to execute
        int last = getLastExec(); // last eid decided

        lm.setNewLeader(leader);

        // If I am not the leader, I have to send a STOPDATE message to it
        if (leader != this.controller.getStaticConf().getProcessId()) {

            try { // serialize content of the SYNC message

                bos = new ByteArrayOutputStream();
                out = new ObjectOutputStream(bos);

                if (last > -1) { // content of the last decided eid

                    out.writeBoolean(true);
                    out.writeInt(last);
                    Execution exec = execManager.getExecution(last);
                    //byte[] decision = exec.getLearner().getDecision();

                    ////// ISTO E PARA APANHAR UM BUG!!!!!
                    if (exec.getDecisionRound() == null || exec.getDecisionRound().propValue == null) {

                        System.out.println("[DEBUG INFO FOR LAST EID #1]");

                        if (exec.getDecisionRound() == null) {
                            System.out.println("No decision round for eid " + last);
                        } else {
                            System.out.println(
                                    "round for eid: " + last + ": " + exec.getDecisionRound().toString());

                            if (exec.getDecisionRound().propValue == null)
                                System.out.println("No propose for eid " + last);
                            else {
                                System.out.println("Propose hash for eid " + last + ": " + Base64
                                        .encodeBase64String(computeHash(exec.getDecisionRound().propValue)));
                            }
                        }

                        return;
                    }

                    byte[] decision = exec.getDecisionRound().propValue;
                    Set<PaxosMessage> proof = exec.getDecisionRound().getProof();

                    out.writeObject(decision);
                    out.writeObject(proof);
                    // TODO: WILL BE NECESSARY TO ADD A PROOF!!!

                }

                else
                    out.writeBoolean(false);

                if (in > -1) { // content of eid in execution

                    Execution exec = execManager.getExecution(in);

                    TimestampValuePair quorumWrites = exec.getQuorumWrites();
                    HashSet<TimestampValuePair> writeSet = exec.getWriteSet();

                    CollectData collect = new CollectData(this.controller.getStaticConf().getProcessId(), in,
                            quorumWrites, writeSet);

                    SignedObject signedCollect = sign(collect);

                    out.writeObject(signedCollect);

                }

                else {

                    CollectData collect = new CollectData(this.controller.getStaticConf().getProcessId(), -1,
                            new TimestampValuePair(-1, new byte[0]), new HashSet<TimestampValuePair>());

                    SignedObject signedCollect = sign(collect);

                    out.writeObject(signedCollect);

                }

                out.flush();
                bos.flush();

                byte[] payload = bos.toByteArray();
                out.close();
                bos.close();

                int[] b = new int[1];
                b[0] = leader;

                Logger.println("(TOMLayer.evaluateStops) sending STOPDATA of regency " + regency);
                // send message SYNC to the new leader
                communication.send(b, new LCMessage(this.controller.getStaticConf().getProcessId(),
                        TOMUtil.STOPDATA, regency, payload));

                //TODO: Turn on timeout again

            } catch (IOException ex) {
                ex.printStackTrace();
                java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                try {
                    out.close();
                    bos.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                    java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

        } else { // If leader, I will store information that I would send in a SYNC message

            Logger.println("(TOMLayer.evaluateStops) I'm the leader for this new regency");
            LastEidData lastData = null;
            CollectData collect = null;

            if (last > -1) { // content of the last decided eid 
                Execution exec = execManager.getExecution(last);
                //byte[] decision = exec.getLearner().getDecision();

                ////// ISTO E PARA APANHAR UM BUG!!!!!
                if (exec.getDecisionRound() == null || exec.getDecisionRound().propValue == null) {

                    System.out.println("[DEBUG INFO FOR LAST EID #2]");

                    if (exec.getDecisionRound() == null)
                        System.out.println("No decision round for eid " + last);
                    else
                        System.out
                                .println("round for eid: " + last + ": " + exec.getDecisionRound().toString());
                    if (exec.getDecisionRound().propValue == null)
                        System.out.println("No propose for eid " + last);
                    else {
                        System.out.println("Propose hash for eid " + last + ": "
                                + Base64.encodeBase64String(computeHash(exec.getDecisionRound().propValue)));
                    }

                    return;
                }

                byte[] decision = exec.getDecisionRound().propValue;
                Set<PaxosMessage> proof = exec.getDecisionRound().getProof();

                lastData = new LastEidData(this.controller.getStaticConf().getProcessId(), last, decision,
                        proof);
                // TODO: WILL BE NECESSARY TO ADD A PROOF!!!

            } else {
                lastData = new LastEidData(this.controller.getStaticConf().getProcessId(), last, null, null);
            }
            lcManager.addLastEid(regency, lastData);

            if (in > -1) { // content of eid being executed
                Execution exec = execManager.getExecution(in);

                TimestampValuePair quorumWrites = exec.getQuorumWrites();
                HashSet<TimestampValuePair> writeSet = exec.getWriteSet();

                collect = new CollectData(this.controller.getStaticConf().getProcessId(), in, quorumWrites,
                        writeSet);

            } else {
                collect = new CollectData(this.controller.getStaticConf().getProcessId(), -1,
                        new TimestampValuePair(-1, new byte[0]), new HashSet<TimestampValuePair>());
            }

            SignedObject signedCollect = sign(collect);

            lcManager.addCollect(regency, signedCollect);
        }

    }
}

From source file:com.flexoodb.common.FlexUtils.java

static public byte[] getBytes(Object obj) throws Exception {
    byte[] b = null;
    ByteArrayOutputStream bos = null;
    ObjectOutputStream oos = null;
    try {/*from   ww w  .j a  v a 2  s  . c  om*/
        bos = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(bos);
        oos.writeObject(obj);
        oos.flush();
        b = bos.toByteArray();
    } catch (Exception e) {
        throw e;
    } finally {
        try {
            oos.close();
            bos.close();
        } catch (Exception f) {
        }
    }
    return b;
}

From source file:paquete.HollywoodUI.java

private void Save_infoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Save_infoActionPerformed
    File archivo_data = new File("./DataGenerated.bin");
    FileOutputStream fos = null;// w ww . j  a v a  2s.c  om
    ObjectOutputStream oos = null;
    try {
        if (!(archivo_data.exists())) {
            fos = new FileOutputStream(archivo_data);
            oos = new ObjectOutputStream(fos);
            oos.writeObject(this.HollyUniverseGraph);
            oos.flush();
            oos.close();
            fos.close();
        }
        JOptionPane.showMessageDialog(this, "Archivo escrito con exito", "EXITO",
                JOptionPane.INFORMATION_MESSAGE);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, "Error al escribir archivo de datos", "ERROR",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:bftsmart.tom.core.Synchronizer.java

/**
 * This method is called when there is a timeout and the request has already
 * been forwarded to the leader/*from   www .  ja v a2  s . c  o m*/
 *
 * @param requestList List of requests that the replica wanted to order but
 * didn't manage to
 */
public void triggerTimeout(List<TOMMessage> requestList) {

    ObjectOutputStream out = null;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    int regency = lcManager.getNextReg();

    requestsTimer.stopTimer();
    requestsTimer.Enabled(false);

    // still not in the leader change phase?
    if (lcManager.getNextReg() == lcManager.getLastReg()) {

        lcManager.setNextReg(lcManager.getLastReg() + 1); // define next timestamp

        regency = lcManager.getNextReg(); // update variable 

        // store messages to be ordered
        lcManager.setCurrentRequestTimedOut(requestList);

        // store information about messages that I'm going to send
        lcManager.addStop(regency, this.controller.getStaticConf().getProcessId());

        //execManager.stop(); // stop consensus execution

        //Get requests that timed out and the requests received in STOP messages
        //and add those STOPed requests to the client manager
        addSTOPedRequestsToClientManager();
        List<TOMMessage> messages = getRequestsToRelay();

        try { // serialize content to send in STOP message
            out = new ObjectOutputStream(bos);

            if (messages != null && messages.size() > 0) {

                //TODO: If this is null, then there was no timeout nor STOP messages.
                //What to do?
                byte[] serialized = bb.makeBatch(messages, 0, 0, controller);
                out.writeBoolean(true);
                out.writeObject(serialized);
            } else {
                out.writeBoolean(false);
                System.out.println(
                        "(Synchronizer.triggerTimeout) Strange... did not include any request in my STOP message for regency "
                                + regency);
            }

            byte[] payload = bos.toByteArray();

            out.flush();
            bos.flush();

            out.close();
            bos.close();

            // send STOP-message                
            System.out.println("(Synchronizer.triggerTimeout) sending STOP message to install regency "
                    + regency + " with " + (messages != null ? messages.size() : 0) + " request(s) to relay");

            LCMessage stop = new LCMessage(this.controller.getStaticConf().getProcessId(), TOMUtil.STOP,
                    regency, payload);
            requestsTimer.setSTOP(regency, stop); // make replica re-transmit the stop message until a new regency is installed
            communication.send(this.controller.getCurrentViewOtherAcceptors(), stop);

        } catch (IOException ex) {
            ex.printStackTrace();
            java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                out.close();
                bos.close();
            } catch (IOException ex) {
                ex.printStackTrace();
                java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }

    processOutOfContextSTOPs(regency); // the replica might have received STOPs
                                       // that were out of context at the time they
                                       // were received, but now can be processed

    startSynchronization(regency); // evaluate STOP messages

}

From source file:es.pode.catalogadorWeb.presentacion.catalogadorBasicPlus.CatBasicPlusControllerImpl.java

private Object deepCopy(Object oldObj) throws Exception {
    ObjectOutputStream oos = null;
    ObjectInputStream ois = null;
    try {/*from   www . j a  v  a  2  s  .  c  o m*/
        ByteArrayOutputStream bos = new ByteArrayOutputStream(); // A
        oos = new ObjectOutputStream(bos); // B
        // serialize and pass the object
        oos.writeObject(oldObj); // C
        oos.flush(); // D
        ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray()); // E
        ois = new ObjectInputStream(bin); // F
        // return the new object
        return ois.readObject(); // G
    } catch (Exception e) {
        System.out.println("Exception in ObjectCloner = " + e);
        throw (e);
    } finally {
        oos.close();
        ois.close();
    }
}