Package org.jgroups.stack

Examples of org.jgroups.stack.StateTransferInfo


     * it should call returnState() to reply with the state of the application
     * @param state The state of the application as a byte buffer
     *              (to send over the network).
     */
    public void returnState(byte[] state) {
        StateTransferInfo info=new StateTransferInfo(null, null, 0L, state);
        down(new Event(Event.GET_APPLSTATE_OK, info));
    }
View Full Code Here


     * Returns a substate as indicated by state_id
     * @param state
     * @param state_id
     */
    public void returnState(byte[] state, String state_id) {
        StateTransferInfo info=new StateTransferInfo(null, state_id, 0L, state);
        down(new Event(Event.GET_APPLSTATE_OK, info));
    }
View Full Code Here

        case Event.DISCONNECT_OK:
            disconnect_promise.setResult(Boolean.TRUE);
            break;

        case Event.GET_STATE_OK:
            StateTransferInfo info=(StateTransferInfo)evt.getArg();
            byte[] state=info.state;

            state_promise.setResult(state != null? Boolean.TRUE : Boolean.FALSE);
            if(up_handler != null) {
                up_handler.up(evt);
                return;
            }

            if(state != null) {
                String state_id=info.state_id;
                if(receiver != null) {
                    if(receiver instanceof ExtendedReceiver && state_id!=null)
                        ((ExtendedReceiver)receiver).setState(state_id, state);
                    else
                        receiver.setState(state);
                }
                else {
                    try {mq.add(new Event(Event.STATE_RECEIVED, info));} catch(Exception e) {}
                }
            }
            break;

        case Event.STATE_TRANSFER_INPUTSTREAM:
            StateTransferInfo sti=(StateTransferInfo)evt.getArg();
            InputStream is=sti.inputStream;
            //Oct 13,2006 moved to down() when Event.STATE_TRANSFER_INPUTSTREAM_CLOSED is received
            //state_promise.setResult(is != null? Boolean.TRUE : Boolean.FALSE);

            if(up_handler != null) {
                up_handler.up(evt);
                return;
            }

            if(is != null) {
                if(receiver instanceof ExtendedReceiver) {
                    if(sti.state_id == null)
                        ((ExtendedReceiver)receiver).setState(is);
                    else
                        ((ExtendedReceiver)receiver).setState(sti.state_id, is);
                }
                else {
                    try {
                        mq.add(new Event(Event.STATE_TRANSFER_INPUTSTREAM, sti));
                    }
                    catch(Exception e) {
                    }
                }
            }
      break;

        case Event.SET_LOCAL_ADDRESS:
            local_addr_promise.setResult(evt.getArg());
            break;

        case Event.EXIT:
            handleExit(evt);
            return// no need to pass event up; already done in handleExit()

        default:
            break;
        }


        // If UpHandler is installed, pass all events to it and return (UpHandler is e.g. a building block)
        if(up_handler != null) {
            up_handler.up(evt);

            if(type == Event.UNBLOCK){
               flush_unblock_promise.setResult(Boolean.TRUE);
            }
            return;
        }

        switch(type) {
            case Event.MSG:
                if(receiver != null) {
                    receiver.receive((Message)evt.getArg());
                    return;
                }
                break;
            case Event.VIEW_CHANGE:
                if(receiver != null) {
                    receiver.viewAccepted((View)evt.getArg());
                    return;
                }
                break;
            case Event.SUSPECT:
                if(receiver != null) {
                    receiver.suspect((Address)evt.getArg());
                    return;
                }
                break;
            case Event.GET_APPLSTATE:
                if(receiver != null) {
                    StateTransferInfo info=(StateTransferInfo)evt.getArg();
                    byte[] tmp_state;
                    String state_id=info.state_id;
                    if(receiver instanceof ExtendedReceiver && state_id!=null) {
                        tmp_state=((ExtendedReceiver)receiver).getState(state_id);
                    }
                    else {
                        tmp_state=receiver.getState();
                    }
                    returnState(tmp_state, state_id);
                    return;
                }
                break;
            case Event.STATE_TRANSFER_OUTPUTSTREAM:
                if(receiver != null) {
                    StateTransferInfo sti=(StateTransferInfo)evt.getArg();
                    OutputStream os=sti.outputStream;
                    if(os != null && receiver instanceof ExtendedReceiver) {
                        if(sti.state_id == null)
                            ((ExtendedReceiver)receiver).getState(os);
                        else
View Full Code Here

            case Event.BLOCK:
                return new BlockEvent();
            case Event.UNBLOCK:
                return new UnblockEvent();
            case Event.GET_APPLSTATE:
                StateTransferInfo info=(StateTransferInfo)evt.getArg();
                return new GetStateEvent(info.target, info.state_id);
            case Event.STATE_RECEIVED:
                info=(StateTransferInfo)evt.getArg();
                return new SetStateEvent(info.state, info.state_id);
            case Event.STATE_TRANSFER_OUTPUTSTREAM:
View Full Code Here


    public void down(Event evt) {
        byte[] state;
        Address target, requester;
        StateTransferInfo info;
        StateHeader hdr;

        switch(evt.getType()) {

            case Event.TMP_VIEW:
            case Event.VIEW_CHANGE:
                handleViewChange((View)evt.getArg());
                break;

            // generated by JChannel.getState(). currently, getting the state from more than 1 mbr is not implemented
            case Event.GET_STATE:
                info=(StateTransferInfo)evt.getArg();
                if(info.target == null) {
                    target=determineCoordinator();
                }
                else {
                    target=info.target;
                    if(target.equals(local_addr)) {
                        if(log.isErrorEnabled()) log.error("GET_STATE: cannot fetch state from myself !");
                        target=null;
                    }
                }
                if(target == null) {
                    if(log.isDebugEnabled()) log.debug("GET_STATE: first member (no state)");
                    passUp(new Event(Event.GET_STATE_OK, new StateTransferInfo()));
                }
                else {
                    boolean successfulFlush = false;
                    if(use_flush) {
                       successfulFlush = startFlush(flush_timeout, 5);
View Full Code Here

        synchronized(state_requesters) {
            Set appl_ids=new HashSet(state_requesters.keySet());
            String id;
            for(Iterator it=appl_ids.iterator(); it.hasNext();) {
                id=(String)it.next();
                StateTransferInfo info=new StateTransferInfo(null, id, 0L, null);
                passUp(new Event(Event.GET_APPLSTATE, info));
            }
        }
    }
View Full Code Here

            if(warn)
                log.warn("state received from " + sender + " is null, will return null state to application");
        }
        else
            log.debug("received state, size=" + state.length + " bytes. Time=" + (stop-start) + " milliseconds");
        StateTransferInfo info=new StateTransferInfo(null, id, 0L, state);
        passUp(new Event(Event.GET_STATE_OK, info));
    }
View Full Code Here

                break;

            // generated by JChannel.getState(). currently, getting the state from more than 1 mbr is not implemented
            case Event.GET_STATE:
                Address target;
                StateTransferInfo info=(StateTransferInfo)evt.getArg();
                if(info.target == null) {
                    target=determineCoordinator();
                }
                else {
                    target=info.target;
                    if(target.equals(local_addr)) {
                        if(log.isErrorEnabled())
                            log.error("GET_STATE: cannot fetch state from myself !");
                        target=null;
                    }
                }
                if(target == null) {
                    if(log.isDebugEnabled())
                        log.debug("GET_STATE: first member (no state)");
                    up_prot.up(new Event(Event.GET_STATE_OK, new StateTransferInfo()));
                }
                else {
                    Message state_req=new Message(target, null, null);
                    state_req.putHeader(getName(), new StateHeader(StateHeader.STATE_REQ,
                                                              local_addr,
View Full Code Here

        Set<String> appl_ids=new HashSet<String>(state_requesters.keySet());

        List<StateTransferInfo> responses=new LinkedList<StateTransferInfo>();
        for(Iterator<String> it=appl_ids.iterator();it.hasNext();) {
            String id=it.next();
            StateTransferInfo info=new StateTransferInfo(requester, id, 0L, null);
            StateTransferInfo rsp=(StateTransferInfo)up_prot.up(new Event(Event.GET_APPLSTATE, info));
            responses.add(rsp);
        }
        if(open_barrier)
            down_prot.down(new Event(Event.OPEN_BARRIER));
        for(StateTransferInfo rsp:responses) {
View Full Code Here

        else
            log.debug("received state, size=" + state.length
                      + " bytes. Time="
                      + (stop - start)
                      + " milliseconds");
        StateTransferInfo info=new StateTransferInfo(state_sender, id, 0L, state);
        up_prot.up(new Event(Event.GET_STATE_OK, info));
    }
View Full Code Here

TOP

Related Classes of org.jgroups.stack.StateTransferInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.