Package org.jgroups.stack

Examples of org.jgroups.stack.StateTransferInfo


                        msg_listener.receive((Message) evt.getArg());
                    }
                    break;

                case Event.GET_APPLSTATE: // reply with GET_APPLSTATE_OK
                    StateTransferInfo info=(StateTransferInfo)evt.getArg();
                    String state_id=info.state_id;
                    byte[] tmp_state=null;
                    if(msg_listener != null) {
                        try {
                            if(msg_listener instanceof ExtendedMessageListener && state_id!=null) {
                                tmp_state=((ExtendedMessageListener)msg_listener).getState(state_id);
                            }
                            else {
                                tmp_state=msg_listener.getState();
                            }
                        }
                        catch(Throwable t) {
                            this.log.error("failed getting state from message listener (" + msg_listener + ')', t);
                        }
                    }
                    return new StateTransferInfo(null, state_id, 0L, tmp_state);

                case Event.GET_STATE_OK:
                    if(msg_listener != null) {
                        try {
                            info=(StateTransferInfo)evt.getArg();
                            String id=info.state_id;
                            if(msg_listener instanceof ExtendedMessageListener && id!=null) {
                                ((ExtendedMessageListener)msg_listener).setState(id, info.state);
                            }
                            else {
                                msg_listener.setState(info.state);
                            }
                        }
                        catch(ClassCastException cast_ex) {
                            if(this.log.isErrorEnabled())
                                this.log.error("received SetStateEvent, but argument " +
                                        evt.getArg() + " is not serializable. Discarding message.");
                        }
                    }
                    break;

                case Event.STATE_TRANSFER_OUTPUTSTREAM:
                    StateTransferInfo sti=(StateTransferInfo)evt.getArg();
                    OutputStream os=sti.outputStream;
                    if(msg_listener instanceof ExtendedMessageListener) {                       
                        if(os != null && msg_listener instanceof ExtendedMessageListener) {
                            if(sti.state_id == null)
                                ((ExtendedMessageListener)msg_listener).getState(os);
                            else
                                ((ExtendedMessageListener)msg_listener).getState(sti.state_id, os);
                        }
                        return new StateTransferInfo(null, os, sti.state_id);
                    }
                    else if(msg_listener instanceof MessageListener){
                        if(log.isWarnEnabled()){
                            log.warn("Channel has STREAMING_STATE_TRANSFER, however,"
                                    + " application does not implement ExtendedMessageListener. State is not transfered");
View Full Code Here


   }

   public void down(Event evt)
   {
      Address target;
      StateTransferInfo info;

      switch (evt.getType())
      {

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

         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) {
View Full Code Here

   private void connectToStateProvider(StateHeader hdr)
   {     
      IpAddress address = hdr.bind_addr;
      String tmp_state_id = hdr.getStateId();
      StreamingInputStreamWrapper wrapper = null;
      StateTransferInfo sti = null;
      final Socket socket = new Socket();
      try
      {
         socket.bind(new InetSocketAddress(bind_addr, 0));
         int bufferSize = socket.getReceiveBufferSize();
         socket.setReceiveBufferSize(socket_buffer_size);
         if (log.isDebugEnabled())
            log.debug("Connecting to state provider " + address.getIpAddress() + ":" + address.getPort()
                  + ", original buffer size was " + bufferSize + " and was reset to " + socket.getReceiveBufferSize());
         socket.connect(new InetSocketAddress(address.getIpAddress(), address.getPort()));
         if (log.isDebugEnabled())
            log.debug("Connected to state provider, my end of the socket is " + socket.getLocalAddress() + ":"
                  + socket.getLocalPort() + " passing inputstream up...");

         //write out our state_id and address so state provider can clear this request
         ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
         out.writeObject(tmp_state_id);
         out.writeObject(local_addr);

         wrapper = new StreamingInputStreamWrapper(socket);
         sti = new StateTransferInfo(hdr.sender, wrapper, tmp_state_id);                 
      }
      catch (IOException e)
      {
         if (warn)
         {
            log.warn("State reader socket thread spawned abnormaly", e);
         }
        
         //pass null stream up so that JChannel.getState() returns false
         InputStream is = null;
         sti = new StateTransferInfo(hdr.sender, is, tmp_state_id);        
      }
      finally
      {
         if (!socket.isConnected())
         {
View Full Code Here

        channel.send(service_msg);
    }


    private void handleStateRequest(Event evt) {
        StateTransferInfo info=(StateTransferInfo)evt.getArg();
        String id=info.state_id;
        String original_id=id;
        MuxChannel mux_ch=null;

        try {
View Full Code Here




    private void handleStateResponse(Event evt) {
        StateTransferInfo info=(StateTransferInfo)evt.getArg();
        MuxChannel mux_ch;

        String appl_id, substate_id, tmp;
        tmp=info.state_id;

        if(tmp == null) {
            if(log.isTraceEnabled())
                log.trace("state is null, not passing up: " + info);
            return;
        }

        int index=tmp.indexOf(SEPARATOR);
        if(index > -1) {
            appl_id=tmp.substring(0, index);
            substate_id=tmp.substring(index+SEPARATOR_LEN);
        }
        else {
            appl_id=tmp;
            substate_id=null;
        }

        mux_ch=(MuxChannel)services.get(appl_id);
        if(mux_ch == null) {
            log.error("didn't find service with ID=" + appl_id + " to fetch state from");
        }
        else {
            StateTransferInfo tmp_info=info.copy();
            tmp_info.state_id=substate_id;
            evt.setArg(tmp_info);
            mux_ch.up(evt); // state_id will be null, get regular state from the service named state_id
        }
    }
View Full Code Here

            String state_id = (String) ois.readObject();
            Address stateRequester = (Address) ois.readObject();
            removeFromStateRequesters(stateRequester, state_id);

            wrapper = new StreamingOutputStreamWrapper(socket);
            StateTransferInfo sti = new StateTransferInfo(stateRequester, wrapper, state_id);
            passUp(new Event(Event.STATE_TRANSFER_OUTPUTSTREAM, sti));
         }
         catch (IOException e)
         {
            if (warn)
View Full Code Here


    public void down(Event evt) {
        Object coord, state;
        Vector event_list;
        StateTransferInfo info;


        switch(evt.getType()) {

            case Event.TMP_VIEW:
            case Event.VIEW_CHANGE:
                Vector new_members=((View)evt.getArg()).getMembers();
                synchronized(members) {
                    members.removeAllElements();
                    if(new_members != null && new_members.size() > 0)
                        for(int k=0; k < new_members.size(); k++)
                            members.addElement(new_members.elementAt(k));
                }
                break;

            case Event.GET_STATE:       // generated by JChannel.getState()
                info=(StateTransferInfo)evt.getArg();
                coord=determineCoordinator();

                if(coord == null || coord.equals(local_addr)) {
                    event_list=new Vector(1);
                    event_list.addElement(new Event(Event.GET_STATE_OK, new StateTransferInfo()));
                    passUp(new Event(Event.STOP_QUEUEING, event_list));
                    return;             // don't pass down any further !
                }



                try {
                    sendMakeCopyMessage()// multicast MAKE_COPY to all members (including me)
                    state=getStateFromSingle(info.target);
                }
                catch(Throwable t) {
                    if(log.isErrorEnabled())
                        log.error("failed sending state request", t);
                    state=null;
                }

                /* Pass up the state to the application layer (insert into JChannel's event queue */
                event_list=new Vector(1);
                event_list.addElement(new Event(Event.GET_STATE_OK, new StateTransferInfo(null, info.state_id, 0L, (byte[])state)));

                /* Now stop queueing */
                passUp(new Event(Event.STOP_QUEUEING, event_list));
                return;                 // don't pass down any further !

View Full Code Here

                        msg_listener.receive((Message) evt.getArg());
                    }
                    break;

                case Event.GET_APPLSTATE: // reply with GET_APPLSTATE_OK
                    StateTransferInfo info=(StateTransferInfo)evt.getArg();
                    String state_id=info.state_id;
                    byte[] tmp_state=null;
                    if(msg_listener != null) {
                        try {
                            if(msg_listener instanceof ExtendedMessageListener && state_id!=null) {
                                tmp_state=((ExtendedMessageListener)msg_listener).getState(state_id);
                            }
                            else {
                                tmp_state=msg_listener.getState();
                            }
                        }
                        catch(Throwable t) {
                            this.log.error("failed getting state from message listener (" + msg_listener + ')', t);
                        }
                    }
                    channel.returnState(tmp_state, state_id);
                    break;

                case Event.GET_STATE_OK:
                    if(msg_listener != null) {
                        try {
                            info=(StateTransferInfo)evt.getArg();
                            String id=info.state_id;
                            if(msg_listener instanceof ExtendedMessageListener && id!=null) {
                                ((ExtendedMessageListener)msg_listener).setState(id, info.state);
                            }
                            else {
                                msg_listener.setState(info.state);
                            }
                        }
                        catch(ClassCastException cast_ex) {
                            if(this.log.isErrorEnabled())
                                this.log.error("received SetStateEvent, but argument " +
                                        evt.getArg() + " is not serializable. Discarding message.");
                        }
                    }
                    break;

                case Event.STATE_TRANSFER_OUTPUTSTREAM:
                    if(msg_listener != null) {
                        StateTransferInfo sti=(StateTransferInfo)evt.getArg();
                        OutputStream os=sti.outputStream;
                        if(os != null && msg_listener instanceof ExtendedMessageListener) {
                            if(sti.state_id == null)
                                ((ExtendedMessageListener)msg_listener).getState(os);
                            else
                                ((ExtendedMessageListener)msg_listener).getState(sti.state_id, os);
                        }
                        return;
                    }
            break;

                case Event.STATE_TRANSFER_INPUTSTREAM:
                    if(msg_listener != null) {
                      StateTransferInfo sti=(StateTransferInfo)evt.getArg();
                        InputStream is=sti.inputStream;
                        if(is!=null && msg_listener instanceof ExtendedMessageListener) {
                            if(sti.state_id == null)
                                ((ExtendedMessageListener)msg_listener).setState(is);
                            else
View Full Code Here

        }
        else {               // only retrieve state from appl when not in client state anymore
            if(is_server) {  // get state from application and store it locally
                synchronized(state_xfer_mutex) {
                    cached_state=null;
                    StateTransferInfo info=new StateTransferInfo(local_addr);
                    passUp(new Event(Event.GET_APPLSTATE, info));
                    if(cached_state == null) {
                        try {
                            state_xfer_mutex.wait(timeout_get_appl_state); // wait for STATE_TRANSFER_OK
                        }
View Full Code Here

            if(log.isTraceEnabled())
                log.trace("cannot get state from myself (" + target + "): probably the first member");
            return false;
        }

        StateTransferInfo info=new StateTransferInfo(target, state_id, timeout);
        boolean rc=_getState(new Event(Event.GET_STATE, info), info);
        if(rc == false)
            down(new Event(Event.RESUME_STABLE));
        return rc;
    }
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.