Package org.jgroups

Examples of org.jgroups.Event


   {
      Runnable readingThread = new Runnable()
      {
         public void run()
         {
            passUp(new Event(Event.STATE_TRANSFER_INPUTSTREAM, sti));
         }
      };
      if (use_reading_thread)
      {
         new Thread(Util.getGlobalThreadGroup(), readingThread, "STREAMING_STATE_TRANSFER.reader").start();
View Full Code Here


          //local_addr=new org.jgroups.stack.IpAddress("localhost", 10000); // fake address
       local_addr = new IpAddress(12345);
    }

    public void start() throws Exception {
        passUp(new Event(Event.SET_LOCAL_ADDRESS, local_addr));
    }
View Full Code Here

                rsp.setSrc(local_addr);

            //dest_addr=msg.getDest();
            //rsp.setDest(local_addr);
            //rsp.setSrc(dest_addr != null ? dest_addr : local_addr);
            up(new Event(Event.MSG, rsp));
            break;

        case Event.GET_LOCAL_ADDRESS:   // return local address -> Event(SET_LOCAL_ADDRESS, local)
            passUp(new Event(Event.SET_LOCAL_ADDRESS, local_addr));
            break;

        case Event.CONNECT:
            group_addr=(String)evt.getArg();
            passUp(new Event(Event.CONNECT_OK));
            break;

        case Event.DISCONNECT:
            passUp(new Event(Event.DISCONNECT_OK));
            break;

        case Event.PERF:
            passUp(evt);
            break;
View Full Code Here

     </pre>
     */
    void fragment(Message msg) {
        byte[]             buffer;
        List               fragments;
        Event              evt;
        FragHeader         hdr;
        Message            frag_msg;
        Address            dest=msg.getDest();
        long               id=getNextId(); // used as seqnos
        int                num_frags;
        StringBuffer       sb;
        Range              r;

        try {
            buffer=msg.getBuffer();
            fragments=Util.computeFragOffsets(buffer, frag_size);
            num_frags=fragments.size();
            synchronized(this) {
                num_sent_frags+=num_frags;
            }

            if(trace) {
                sb=new StringBuffer("fragmenting packet to ");
                sb.append((dest != null ? dest.toString() : "<all members>")).append(" (size=").append(buffer.length);
                sb.append(") into ").append(num_frags).append(" fragment(s) [frag_size=").append(frag_size).append(']');
                log.trace(sb.toString());
            }

            for(int i=0; i < fragments.size(); i++) {
                r=(Range)fragments.get(i);
                // Copy the original msg (needed because we need to copy the headers too)
                frag_msg=msg.copy(false); // don't copy the buffer, only src, dest and headers
                frag_msg.setBuffer(buffer, (int)r.low, (int)r.high);
                hdr=new FragHeader(id, i, num_frags);
                frag_msg.putHeader(name, hdr);
                evt=new Event(Event.MSG, frag_msg);
                passDown(evt);
            }
        }
        catch(Exception e) {
            if(log.isErrorEnabled()) log.error("fragmentation failure", e);
View Full Code Here

        if(assembled_msg != null) {
            try {
                if(trace) log.trace("assembled_msg is " + assembled_msg);
                assembled_msg.setSrc(sender); // needed ? YES, because fragments have a null src !!
                num_received_msgs++;
                passUp(new Event(Event.MSG, assembled_msg));
            }
            catch(Exception e) {
                if(log.isErrorEnabled()) log.error("unfragmentation failed", e);
            }
        }
View Full Code Here

     */
    private void fragment(Message msg) {
        DataOutputStream   out=null;
        byte[]             buffer;
        byte[]             fragments[];
        Event              evt;
        FragHeader         hdr;
        Message            frag_msg;
        Address            dest=msg.getDest(), src=msg.getSrc();
        long               id=curr_id++; // used as seqnos
        int                num_frags;
        int size;

        try {
            // Write message into a byte buffer and fragment it
            // Synchronization around bos is needed for concurrent access (http://jira.jboss.com/jira/browse/JGRP-215)
            synchronized(bos) {
                bos.reset();
                out=new DataOutputStream(bos);
                msg.writeTo(out);
                out.flush();
                buffer=bos.getRawBuffer();
                fragments=Util.fragmentBuffer(buffer, frag_size, bos.size());
            }

            num_frags=fragments.length;
            num_sent_frags+=num_frags;

            if(trace) {
                StringBuffer sb=new StringBuffer();
                sb.append("fragmenting packet to ").append(dest != null ? dest.toString() : "<all members>");
                sb.append(" (size=").append(buffer.length).append(") into ").append(num_frags);
                sb.append(" fragment(s) [frag_size=").append(frag_size).append(']');
                log.trace(sb.toString());
            }

            for(int i=0; i < num_frags; i++) {
                frag_msg=new Message(dest, src, fragments[i]);
                hdr=new FragHeader(id, i, num_frags);
                frag_msg.putHeader(name, hdr);
                evt=new Event(Event.MSG, frag_msg);
                passDown(evt);
            }
        }
        catch(Exception e) {
            log.error("exception occurred trying to fragment message", e);
View Full Code Here

                assembled_msg=new Message(false);
                assembled_msg.readFrom(in);
                if(trace) log.trace("assembled_msg is " + assembled_msg);
                assembled_msg.setSrc(sender); // needed ? YES, because fragments have a null src !!
                num_received_msgs++;
                passUp(new Event(Event.MSG, assembled_msg));
            }
            catch(Exception e) {
                log.error("failed unfragmenting a message", e);
            }
            finally {
View Full Code Here

            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

         {
            log.debug("State reader " + inputStreamOwner + " is closing the socket ");
         }
         if (channelOwner != null && channelOwner.isConnected())
         {
            channelOwner.down(new Event(Event.STATE_TRANSFER_INPUTSTREAM_CLOSED));
         }
         inputStreamOwner.close();
      }
View Full Code Here

         }
         try
         {
            if (channelOwner != null && channelOwner.isConnected())
            {
               channelOwner.down(new Event(Event.STATE_TRANSFER_OUTPUTSTREAM_CLOSED));
            }          
            outputStreamOwner.close();
         }
         catch (IOException e)
         {
View Full Code Here

TOP

Related Classes of org.jgroups.Event

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.