Package org.jgroups

Examples of org.jgroups.Address


       /**
        * Reads the peer's address. First a cookie has to be sent which has to match my own cookie, otherwise
        * the connection will be refused
        */
       Address readPeerAddress(Socket client_sock) throws Exception {
           Address     client_peer_addr=null;
           byte[]      input_cookie=new byte[cookie.length];
           int         client_port=client_sock != null? client_sock.getPort() : 0;
           short       version;
           InetAddress client_addr=client_sock != null? client_sock.getInetAddress() : null;

           if(in != null) {
               initCookie(input_cookie);

               // read the cookie first
               in.read(input_cookie, 0, input_cookie.length);
               if(!matchCookie(input_cookie))
                   throw new SocketException("ConnectionTable.Connection.readPeerAddress(): cookie sent by " +
                                             client_peer_addr + " does not match own cookie; terminating connection");
               // then read the version
               version=in.readShort();

               if(Version.compareTo(version) == false) {
                   if(log.isWarnEnabled())
                       log.warn(new StringBuffer("packet from ").append(client_addr).append(':').append(client_port).
                              append(" has different version (").append(version).append(") from ours (").
                                append(Version.version).append("). This may cause problems"));
               }
               client_peer_addr=new IpAddress();
               client_peer_addr.readFrom(in);

               updateLastAccessed();
           }
           return client_peer_addr;
       }
View Full Code Here


            //don't do anything if this dude is sending out the view change
            //we are receiving a view change,
            //in here we check for the
            View view=(View)evt.getArg();
            Vector new_mbrs=view.getMembers(), left_mbrs;
            Address mbr;

            left_mbrs=Util.determineLeftMembers(members, new_mbrs);
            members.clear();
            members.addAll(new_mbrs);
View Full Code Here

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

     4. Set headers and buffer in msg
     5. Pass msg up the stack
     */
    void unfragment(Message msg) {
        FragmentationTable frag_table;
        Address            sender=msg.getSrc();
        Message            assembled_msg;
        FragHeader         hdr=(FragHeader)msg.removeHeader(name);

        frag_table=fragment_list.get(sender);
        if(frag_table == null) {
View Full Code Here

            //don't do anything if this dude is sending out the view change
            //we are receiving a view change,
            //in here we check for the
            View view=(View)evt.getArg();
            Vector new_mbrs=view.getMembers(), left_mbrs;
            Address mbr;

            left_mbrs=Util.determineLeftMembers(members, new_mbrs);
            members.clear();
            members.addAll(new_mbrs);
View Full Code Here

        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());
            }
View Full Code Here

     * 4. Set headers and buffer in msg
     * 5. Pass msg up the stack
     */
    private void unfragment(Message msg) {
        FragmentationTable   frag_table;
        Address              sender=msg.getSrc();
        Message              assembled_msg;
        FragHeader           hdr=(FragHeader)msg.removeHeader(name);
        byte[]               m;
        ByteArrayInputStream bis;
        DataInputStream      in=null;
View Full Code Here

                     + " and was reset to " + socket.getSendBufferSize() + ", passing outputstream up... ");

            //read out state requesters state_id and address and clear this request
            ois = new ObjectInputStream(socket.getInputStream());
            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));
View Full Code Here

     * passed up the stack.
     */
    public boolean handleUpEvent(Event evt) {
        if(evt.getType() == Event.MSG) {
            Message msg=(Message)evt.getArg();
            Address src=msg.getSrc();
            FCInfo fcForSrc=(FCInfo)_rcvdMSGCounter.get(src);
            if(fcForSrc == null) {
                fcForSrc=new FCInfo();
                _rcvdMSGCounter.put(src, fcForSrc);
            }
View Full Code Here

     *
     * @return Object containing FC information for sender with senderID.
     *         <b>Callback</b>. Called when a request for this protocol layer is received.
     */
    public Object handle(Message req) {
        Address src=req.getSrc();
        Long resp=new Long(((FCInfo)_rcvdMSGCounter.get(src)).getRcvdMSGCount());

        if(log.isInfoEnabled()) log.info("Reqest came from " + src + " Prepared response " + resp);
        return resp;
    }
View Full Code Here

TOP

Related Classes of org.jgroups.Address

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.