org.apache.catalina.tribes.membership.MemberImpl Java Examples

The following examples show how to use org.apache.catalina.tribes.membership.MemberImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TcpFailureDetector.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
protected void performForcedCheck() {
    //update all alive times
    Member[] members = super.getMembers();
    for (int i = 0; members != null && i < members.length; i++) {
        if (memberAlive(members[i])) {
            if (membership.memberAlive((MemberImpl)members[i])) super.memberAdded(members[i]);
            addSuspects.remove(members[i]);
        } else {
            if (membership.getMember(members[i])!=null) {
                membership.removeMember((MemberImpl)members[i]);
                removeSuspects.remove(members[i]);
                if (members[i] instanceof StaticMember) {
                    addSuspects.put(members[i], Long.valueOf(System.currentTimeMillis()));
                }
                super.memberDisappeared(members[i]);
            }
        } //end if
    } //for

}
 
Example #2
Source File: NonBlockingCoordinator.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void memberDisappeared(Member member) {
    try {
        
        membership.removeMember((MemberImpl)member);
        super.memberDisappeared(member);
        try {
            fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_MBR_DEL,this,"Member remove("+member.getName()+")"));
            if ( started && (isCoordinator() || isHighest()) ) 
                startElection(true); //to do, if a member disappears, only the coordinator can start
        }catch ( ChannelException x ) {
            log.error("Unable to start election when member was removed.",x);
        }
    }finally {
    }
}
 
Example #3
Source File: NonBlockingCoordinator.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void heartbeat() {
    try {
        MemberImpl local = (MemberImpl)getLocalMember(false);
        if ( view != null && (Arrays.diff(view,membership,local).length != 0 ||  Arrays.diff(membership,view,local).length != 0) ) {
            if ( isHighest() ) {
                fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_START_ELECT, this,
                                                           "Heartbeat found inconsistency, restart election"));
                startElection(true);
            }            
        }
    } catch ( Exception x  ){
        log.error("Unable to perform heartbeat.",x);
    } finally {
        super.heartbeat();
    }
}
 
Example #4
Source File: NonBlockingCoordinator.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
protected void handleViewConf(CoordinationMessage msg, Member sender,Membership merged) throws ChannelException {
    if ( viewId != null && msg.getId().equals(viewId) ) return;//we already have this view
    view = new Membership((MemberImpl)getLocalMember(false),AbsoluteOrder.comp,true);
    Arrays.fill(view,msg.getMembers());
    viewId = msg.getId();
    
    if ( viewId.equals(suggestedviewId) ) {
        suggestedView = null;
        suggestedviewId = null;
    }
    
    if (suggestedView != null && AbsoluteOrder.comp.compare(suggestedView.getMembers()[0],merged.getMembers()[0])<0 ) {
        suggestedView = null;
        suggestedviewId = null;
    }
    
    viewChange(viewId,view.getMembers());
    fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_CONF_RX,this,"Accepted View"));
    
    if ( suggestedviewId == null && hasHigherPriority(merged.getMembers(),membership.getMembers()) ) {
        startElection(false);
    }
}
 
Example #5
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
protected void handleViewConf(CoordinationMessage msg, Member sender,Membership merged) throws ChannelException {
    if ( viewId != null && msg.getId().equals(viewId) ) return;//we already have this view
    view = new Membership((MemberImpl)getLocalMember(false),AbsoluteOrder.comp,true);
    Arrays.fill(view,msg.getMembers());
    viewId = msg.getId();
    
    if ( viewId.equals(suggestedviewId) ) {
        suggestedView = null;
        suggestedviewId = null;
    }
    
    if (suggestedView != null && AbsoluteOrder.comp.compare(suggestedView.getMembers()[0],merged.getMembers()[0])<0 ) {
        suggestedView = null;
        suggestedviewId = null;
    }
    
    viewChange(viewId,view.getMembers());
    fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_CONF_RX,this,"Accepted View"));
    
    if ( suggestedviewId == null && hasHigherPriority(merged.getMembers(),membership.getMembers()) ) {
        startElection(false);
    }
}
 
Example #6
Source File: NonBlockingCoordinator.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
protected void handleMyToken(MemberImpl local, CoordinationMessage msg, Member sender,Membership merged) throws ChannelException {
    if ( local.equals(msg.getLeader()) ) {
        //no leadership change
        if ( Arrays.sameMembers(msg.getMembers(),merged.getMembers()) ) {
            msg.type = COORD_CONF;
            super.sendMessage(Arrays.remove(msg.getMembers(),local),createData(msg,local),null);
            handleViewConf(msg,local,merged);
        } else {
            //membership change
            suggestedView = new Membership(local,AbsoluteOrder.comp,true);
            suggestedviewId = msg.getId();
            Arrays.fill(suggestedView,merged.getMembers());
            msg.view = merged.getMembers();
            sendElectionMsgToNextInline(local,msg);
        }
    } else {
        //leadership change
        suggestedView = null;
        suggestedviewId = null;
        msg.view = merged.getMembers();
        sendElectionMsgToNextInline(local,msg);
    }
}
 
Example #7
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
protected void handleMyToken(MemberImpl local, CoordinationMessage msg, Member sender,Membership merged) throws ChannelException {
    if ( local.equals(msg.getLeader()) ) {
        //no leadership change
        if ( Arrays.sameMembers(msg.getMembers(),merged.getMembers()) ) {
            msg.type = COORD_CONF;
            super.sendMessage(Arrays.remove(msg.getMembers(),local),createData(msg,local),null);
            handleViewConf(msg,local,merged);
        } else {
            //membership change
            suggestedView = new Membership(local,AbsoluteOrder.comp,true);
            suggestedviewId = msg.getId();
            Arrays.fill(suggestedView,merged.getMembers());
            msg.view = merged.getMembers();
            sendElectionMsgToNextInline(local,msg);
        }
    } else {
        //leadership change
        suggestedView = null;
        suggestedviewId = null;
        msg.view = merged.getMembers();
        sendElectionMsgToNextInline(local,msg);
    }
}
 
Example #8
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void memberDisappeared(Member member) {
    try {
        
        membership.removeMember((MemberImpl)member);
        super.memberDisappeared(member);
        try {
            fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_MBR_DEL,this,"Member remove("+member.getName()+")"));
            if ( started && (isCoordinator() || isHighest()) ) 
                startElection(true); //to do, if a member disappears, only the coordinator can start
        }catch ( ChannelException x ) {
            log.error("Unable to start election when member was removed.",x);
        }
    }finally {
    }
}
 
Example #9
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void heartbeat() {
    try {
        MemberImpl local = (MemberImpl)getLocalMember(false);
        if ( view != null && (Arrays.diff(view,membership,local).length != 0 ||  Arrays.diff(membership,view,local).length != 0) ) {
            if ( isHighest() ) {
                fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_START_ELECT, this,
                                                           "Heartbeat found inconsistency, restart election"));
                startElection(true);
            }            
        }
    } catch ( Exception x  ){
        log.error("Unable to perform heartbeat.",x);
    } finally {
        super.heartbeat();
    }
}
 
Example #10
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
protected void sendElectionMsgToNextInline(MemberImpl local, CoordinationMessage msg) throws ChannelException { 
    int next = Arrays.nextIndex(local,msg.getMembers());
    int current = next;
    msg.leader = msg.getMembers()[0];
    boolean sent =  false;
    while ( !sent && current >= 0 ) {
        try {
            sendElectionMsg(local, msg.getMembers()[current], msg);
            sent = true;
        }catch ( ChannelException x  ) {
            log.warn("Unable to send election message to:"+msg.getMembers()[current]);
            current = Arrays.nextIndex(msg.getMembers()[current],msg.getMembers());
            if ( current == next ) throw x;
        }
    }
}
 
Example #11
Source File: NonBlockingCoordinator.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
protected void sendElectionMsgToNextInline(MemberImpl local, CoordinationMessage msg) throws ChannelException { 
    int next = Arrays.nextIndex(local,msg.getMembers());
    int current = next;
    msg.leader = msg.getMembers()[0];
    boolean sent =  false;
    while ( !sent && current >= 0 ) {
        try {
            sendElectionMsg(local, msg.getMembers()[current], msg);
            sent = true;
        }catch ( ChannelException x  ) {
            log.warn("Unable to send election message to:"+msg.getMembers()[current]);
            current = Arrays.nextIndex(msg.getMembers()[current],msg.getMembers());
            if ( current == next ) throw x;
        }
    }
}
 
Example #12
Source File: TcpFailureDetector.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
protected void performForcedCheck() {
    //update all alive times
    Member[] members = super.getMembers();
    for (int i = 0; members != null && i < members.length; i++) {
        if (memberAlive(members[i])) {
            if (membership.memberAlive((MemberImpl)members[i])) super.memberAdded(members[i]);
            addSuspects.remove(members[i]);
        } else {
            if (membership.getMember(members[i])!=null) {
                membership.removeMember((MemberImpl)members[i]);
                removeSuspects.remove(members[i]);
                if (members[i] instanceof StaticMember) {
                    addSuspects.put(members[i], Long.valueOf(System.currentTimeMillis()));
                }
                super.memberDisappeared(members[i]);
            }
        } //end if
    } //for

}
 
Example #13
Source File: TcpFailureDetector.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void memberAdded(Member member) {
    if ( membership == null ) setupMembership();
    boolean notify = false;
    synchronized (membership) {
        if (removeSuspects.containsKey(member)) {
            //previously marked suspect, system below picked up the member again
            removeSuspects.remove(member);
        } else if (membership.getMember(member) == null){
            //if we add it here, then add it upwards too
            //check to see if it is alive
            if (memberAlive(member)) {
                membership.memberAlive( (MemberImpl) member);
                notify = true;
            } else {
                addSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
            }
        }
    }
    if ( notify ) super.memberAdded(member);
}
 
Example #14
Source File: TcpFailureDetector.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void memberAdded(Member member) {
    if ( membership == null ) setupMembership();
    boolean notify = false;
    synchronized (membership) {
        if (removeSuspects.containsKey(member)) {
            //previously marked suspect, system below picked up the member again
            removeSuspects.remove(member);
        } else if (membership.getMember(member) == null){
            //if we add it here, then add it upwards too
            //check to see if it is alive
            if (memberAlive(member)) {
                membership.memberAlive( (MemberImpl) member);
                notify = true;
            } else {
                addSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
            }
        }
    }
    if ( notify ) super.memberAdded(member);
}
 
Example #15
Source File: ChannelData.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
public byte[] getDataPackage(byte[] data, int offset)  {
    byte[] addr = ((MemberImpl)address).getData(false);
    XByteBuffer.toBytes(options,data,offset);
    offset += 4; //options
    XByteBuffer.toBytes(timestamp,data,offset);
    offset += 8; //timestamp
    XByteBuffer.toBytes(uniqueId.length,data,offset);
    offset += 4; //uniqueId.length
    System.arraycopy(uniqueId,0,data,offset,uniqueId.length);
    offset += uniqueId.length; //uniqueId data
    XByteBuffer.toBytes(addr.length,data,offset);
    offset += 4; //addr.length
    System.arraycopy(addr,0,data,offset,addr.length);
    offset += addr.length; //addr data
    XByteBuffer.toBytes(message.getLength(),data,offset);
    offset += 4; //message.length
    System.arraycopy(message.getBytesDirect(),0,data,offset,message.getLength());
    offset += message.getLength(); //message data
    return data;
}
 
Example #16
Source File: ChannelData.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
public byte[] getDataPackage(byte[] data, int offset)  {
    byte[] addr = ((MemberImpl)address).getData(false);
    XByteBuffer.toBytes(options,data,offset);
    offset += 4; //options
    XByteBuffer.toBytes(timestamp,data,offset);
    offset += 8; //timestamp
    XByteBuffer.toBytes(uniqueId.length,data,offset);
    offset += 4; //uniqueId.length
    System.arraycopy(uniqueId,0,data,offset,uniqueId.length);
    offset += uniqueId.length; //uniqueId data
    XByteBuffer.toBytes(addr.length,data,offset);
    offset += 4; //addr.length
    System.arraycopy(addr,0,data,offset,addr.length);
    offset += addr.length; //addr data
    XByteBuffer.toBytes(message.getLength(),data,offset);
    offset += 4; //message.length
    System.arraycopy(message.getBytesDirect(),0,data,offset,message.getLength());
    offset += message.getLength(); //message data
    return data;
}
 
Example #17
Source File: ChannelData.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
public static ChannelData getDataFromPackage(byte[] b)  {
    ChannelData data = new ChannelData(false);
    int offset = 0;
    data.setOptions(XByteBuffer.toInt(b,offset));
    offset += 4; //options
    data.setTimestamp(XByteBuffer.toLong(b,offset));
    offset += 8; //timestamp
    data.uniqueId = new byte[XByteBuffer.toInt(b,offset)];
    offset += 4; //uniqueId length
    System.arraycopy(b,offset,data.uniqueId,0,data.uniqueId.length);
    offset += data.uniqueId.length; //uniqueId data
    byte[] addr = new byte[XByteBuffer.toInt(b,offset)];
    offset += 4; //addr length
    System.arraycopy(b,offset,addr,0,addr.length);
    data.setAddress(MemberImpl.getMember(addr));
    offset += addr.length; //addr data
    int xsize = XByteBuffer.toInt(b,offset);
    //data.message = new XByteBuffer(new byte[xsize],false);
    data.message = BufferPool.getBufferPool().getBuffer(xsize,false);
    offset += 4; //message length
    System.arraycopy(b,offset,data.message.getBytesDirect(),0,xsize);
    data.message.append(b,offset,xsize);
    offset += xsize; //message data
    return data;
}
 
Example #18
Source File: ChannelData.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
public static ChannelData getDataFromPackage(byte[] b)  {
    ChannelData data = new ChannelData(false);
    int offset = 0;
    data.setOptions(XByteBuffer.toInt(b,offset));
    offset += 4; //options
    data.setTimestamp(XByteBuffer.toLong(b,offset));
    offset += 8; //timestamp
    data.uniqueId = new byte[XByteBuffer.toInt(b,offset)];
    offset += 4; //uniqueId length
    System.arraycopy(b,offset,data.uniqueId,0,data.uniqueId.length);
    offset += data.uniqueId.length; //uniqueId data
    byte[] addr = new byte[XByteBuffer.toInt(b,offset)];
    offset += 4; //addr length
    System.arraycopy(b,offset,addr,0,addr.length);
    data.setAddress(MemberImpl.getMember(addr));
    offset += addr.length; //addr data
    int xsize = XByteBuffer.toInt(b,offset);
    //data.message = new XByteBuffer(new byte[xsize],false);
    data.message = BufferPool.getBufferPool().getBuffer(xsize,false);
    offset += 4; //message length
    System.arraycopy(b,offset,data.message.getBytesDirect(),0,xsize);
    data.message.append(b,offset,xsize);
    offset += xsize; //message data
    return data;
}
 
Example #19
Source File: ChannelData.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public static ChannelData getDataFromPackage(byte[] b)  {
    ChannelData data = new ChannelData(false);
    int offset = 0;
    data.setOptions(XByteBuffer.toInt(b,offset));
    offset += 4; //options
    data.setTimestamp(XByteBuffer.toLong(b,offset));
    offset += 8; //timestamp
    data.uniqueId = new byte[XByteBuffer.toInt(b,offset)];
    offset += 4; //uniqueId length
    System.arraycopy(b,offset,data.uniqueId,0,data.uniqueId.length);
    offset += data.uniqueId.length; //uniqueId data
    byte[] addr = new byte[XByteBuffer.toInt(b,offset)];
    offset += 4; //addr length
    System.arraycopy(b,offset,addr,0,addr.length);
    data.setAddress(MemberImpl.getMember(addr));
    offset += addr.length; //addr data
    int xsize = XByteBuffer.toInt(b,offset);
    //data.message = new XByteBuffer(new byte[xsize],false);
    data.message = BufferPool.getBufferPool().getBuffer(xsize,false);
    offset += 4; //message length
    System.arraycopy(b,offset,data.message.getBytesDirect(),0,xsize);
    data.message.append(b,offset,xsize);
    offset += xsize; //message data
    return data;
}
 
Example #20
Source File: ChannelData.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public int getDataPackageLength() {
    int length = 
        4 + //options
        8 + //timestamp  off=4
        4 + //unique id length off=12
        uniqueId.length+ //id data off=12+uniqueId.length
        4 + //addr length off=12+uniqueId.length+4
        ((MemberImpl)address).getDataLength()+ //member data off=12+uniqueId.length+4+add.length
        4 + //message length off=12+uniqueId.length+4+add.length+4
        message.getLength();
    return length;

}
 
Example #21
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
protected Membership mergeOnArrive(CoordinationMessage msg, Member sender) {
    fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_PRE_MERGE,this,"Pre merge"));
    MemberImpl local = (MemberImpl)getLocalMember(false);
    Membership merged = new Membership(local,AbsoluteOrder.comp,true);
    Arrays.fill(merged,msg.getMembers());
    Arrays.fill(merged,getMembers());
    Member[] diff = Arrays.diff(merged,membership,local);
    for ( int i=0; i<diff.length; i++ ) {
        if (!alive(diff[i])) merged.removeMember((MemberImpl)diff[i]);
        else memberAdded(diff[i],false);
    }
    fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_POST_MERGE,this,"Post merge"));
    return merged;
}
 
Example #22
Source File: ChannelData.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Deserializes a ChannelData object from a byte array
 * @param xbuf byte[]
 * @return ChannelData
 */
public static ChannelData getDataFromPackage(XByteBuffer xbuf)  {
    ChannelData data = new ChannelData(false);
    int offset = 0;
    data.setOptions(XByteBuffer.toInt(xbuf.getBytesDirect(),offset));
    offset += 4; //options
    data.setTimestamp(XByteBuffer.toLong(xbuf.getBytesDirect(),offset));
    offset += 8; //timestamp
    data.uniqueId = new byte[XByteBuffer.toInt(xbuf.getBytesDirect(),offset)];
    offset += 4; //uniqueId length
    System.arraycopy(xbuf.getBytesDirect(),offset,data.uniqueId,0,data.uniqueId.length);
    offset += data.uniqueId.length; //uniqueId data
    //byte[] addr = new byte[XByteBuffer.toInt(xbuf.getBytesDirect(),offset)];
    int addrlen = XByteBuffer.toInt(xbuf.getBytesDirect(),offset);
    offset += 4; //addr length
    //System.arraycopy(xbuf.getBytesDirect(),offset,addr,0,addr.length);
    data.setAddress(MemberImpl.getMember(xbuf.getBytesDirect(),offset,addrlen));
    //offset += addr.length; //addr data
    offset += addrlen;
    int xsize = XByteBuffer.toInt(xbuf.getBytesDirect(),offset);
    offset += 4; //xsize length
    System.arraycopy(xbuf.getBytesDirect(),offset,xbuf.getBytesDirect(),0,xsize);
    xbuf.setLength(xsize);
    data.message = xbuf;
    return data;

}
 
Example #23
Source File: Arrays.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public static Member[] diff(Membership complete, Membership local, MemberImpl ignore) {
    ArrayList<Member> result = new ArrayList<Member>();
    MemberImpl[] comp = complete.getMembers();
    for ( int i=0; i<comp.length; i++ ) {
        if ( ignore!=null && ignore.equals(comp[i]) ) continue;
        if ( local.getMember(comp[i]) == null ) result.add(comp[i]);
    }
    return result.toArray(new MemberImpl[result.size()]);
}
 
Example #24
Source File: NioSenderTest.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public void init() throws Exception {
    synchronized (Selector.class) {
        // Selector.open() isn't thread safe
        // http://bugs.sun.com/view_bug.do?bug_id=6427854
        // Affects 1.6.0_29, fixed in 1.7.0_01
        selector = Selector.open();
    }
    mbr = new MemberImpl("localhost",4444,0);
    NioSender sender = new NioSender();
    sender.setDestination(mbr);
    sender.setDirectBuffer(true);
    sender.setSelector(selector);
    sender.setMessage(XByteBuffer.createDataPackage(getMessage(mbr)));
    sender.connect();
}
 
Example #25
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public ChannelData createData(CoordinationMessage msg, MemberImpl local) {
    msg.write();
    ChannelData data = new ChannelData(true);
    data.setAddress(local);
    data.setMessage(msg.getBuffer());
    data.setOptions(Channel.SEND_OPTIONS_USE_ACK);
    data.setTimestamp(System.currentTimeMillis());
    return data;
}
 
Example #26
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public Member getNextInLine(MemberImpl local, MemberImpl[] others) {
    MemberImpl result = null;
    for ( int i=0; i<others.length; i++ ) {
        
    }
    return result;
}
 
Example #27
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private CoordinationMessage createElectionMsg(MemberImpl local, MemberImpl[] others, MemberImpl leader) {
    Membership m = new Membership(local,AbsoluteOrder.comp,true);
    Arrays.fill(m,others);
    MemberImpl[] mbrs = m.getMembers();
    m.reset(); 
    CoordinationMessage msg = new CoordinationMessage(leader, local, mbrs,new UniqueId(UUIDGenerator.randomUUID(true)), COORD_REQUEST);
    return msg;
}
 
Example #28
Source File: AbstractReplicatedMap.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated  Unused - will be removed in 8.0.x
 */
@Deprecated
protected void writeMembers(ObjectOutput out,Member[] members) throws IOException {
    if ( members == null ) members = new Member[0];
    out.writeInt(members.length);
    for (int i=0; i<members.length; i++ ) {
        if ( members[i] != null ) {
            byte[] d = members[i] != null ? ( (MemberImpl)members[i]).getData(false) : new byte[0];
            out.writeInt(d.length);
            out.write(d);
        }
    }
}
 
Example #29
Source File: AbstractReplicatedMap.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated  Unused - will be removed in 8.0.x
 */
@Deprecated
protected Member[] readMembers(ObjectInput in) throws IOException {
    int nodecount = in.readInt();
    Member[] members = new Member[nodecount];
    for ( int i=0; i<members.length; i++ ) {
        byte[] d = new byte[in.readInt()];
        in.readFully(d);
        if (d.length > 0) members[i] = MemberImpl.getMember(d);
    }
    return members;
}
 
Example #30
Source File: SocketNioReceive.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Member mbr = new MemberImpl("localhost", 9999, 0);
    ChannelData data = new ChannelData();
    data.setAddress(mbr);
    byte[] buf = new byte[8192 * 4];
    data.setMessage(new XByteBuffer(buf, false));
    buf = XByteBuffer.createDataPackage(data);
    len = buf.length;
    NioReceiver receiver = new NioReceiver();
    receiver.setPort(9999);
    receiver.setHost("localhost");
    MyList list = new MyList();
    receiver.setMessageListener(list);
    receiver.start();
    System.out.println("Listening on 9999");
    while (true) {
        try {
            synchronized (mutex) {
                mutex.wait(5000);
                if ( start != 0 ) {
                    System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds, messages "+count+" accepts "+accept+", total "+mb+" MB.");
                }
            }
        }catch (Throwable x) {
            x.printStackTrace();
        }
    }
}