org.apache.catalina.tribes.UniqueId Java Examples

The following examples show how to use org.apache.catalina.tribes.UniqueId. 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: ChannelCoordinator.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Send a message to one or more members in the cluster
 * @param destination Member[] - the destinations, null or zero length means all
 * @param msg ClusterMessage - the message to send
 * @param payload TBA
 */
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload)
        throws ChannelException {
    if ( destination == null ) destination = membershipService.getMembers();
    if ((msg.getOptions()&Channel.SEND_OPTIONS_MULTICAST) == Channel.SEND_OPTIONS_MULTICAST) {
        membershipService.broadcast(msg);
    } else {
        clusterSender.sendMessage(msg,destination);
    }
    if ( Logs.MESSAGES.isTraceEnabled() ) {
        Logs.MESSAGES.trace("ChannelCoordinator - Sent msg:" + new UniqueId(msg.getUniqueId()) +
                " at " + new java.sql.Timestamp(System.currentTimeMillis()) + " to " +
                Arrays.toNameString(destination));
    }
}
 
Example #2
Source File: TwoPhaseCommitInterceptor.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void heartbeat() {
    try {
        long now = System.currentTimeMillis();
        @SuppressWarnings("unchecked")
        Map.Entry<UniqueId,MapEntry>[] entries = messages.entrySet().toArray(new Map.Entry[messages.size()]);
        for (int i=0; i<entries.length; i++ ) {
            MapEntry entry = entries[i].getValue();
            if ( entry.expired(now,expire) ) {
                if(log.isInfoEnabled())
                    log.info("Message ["+entry.id+"] has expired. Removing.");
                messages.remove(entry.id);
            }//end if
        }
    } catch ( Exception x ) {
        log.warn("Unable to perform heartbeat on the TwoPhaseCommit interceptor.",x);
    } finally {
        super.heartbeat();
    }
}
 
Example #3
Source File: TwoPhaseCommitInterceptor.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void heartbeat() {
    try {
        long now = System.currentTimeMillis();
        @SuppressWarnings("unchecked")
        Map.Entry<UniqueId,MapEntry>[] entries = messages.entrySet().toArray(new Map.Entry[messages.size()]);
        for (int i=0; i<entries.length; i++ ) {
            MapEntry entry = entries[i].getValue();
            if ( entry.expired(now,expire) ) {
                if(log.isInfoEnabled())
                    log.info("Message ["+entry.id+"] has expired. Removing.");
                messages.remove(entry.id);
            }//end if
        }
    } catch ( Exception x ) {
        log.warn("Unable to perform heartbeat on the TwoPhaseCommit interceptor.",x);
    } finally {
        super.heartbeat();
    }
}
 
Example #4
Source File: TwoPhaseCommitInterceptor.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void heartbeat() {
    try {
        long now = System.currentTimeMillis();
        @SuppressWarnings("unchecked")
        Map.Entry<UniqueId,MapEntry>[] entries = messages.entrySet().toArray(new Map.Entry[messages.size()]);
        for (int i=0; i<entries.length; i++ ) {
            MapEntry entry = entries[i].getValue();
            if ( entry.expired(now,expire) ) {
                if(log.isInfoEnabled())
                    log.info("Message ["+entry.id+"] has expired. Removing.");
                messages.remove(entry.id);
            }//end if
        }
    } catch ( Exception x ) {
        log.warn(sm.getString("twoPhaseCommitInterceptor.heartbeat.failed"),x);
    } finally {
        super.heartbeat();
    }
}
 
Example #5
Source File: NonBlockingCoordinator.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public void parse() {
    //header
    int offset = 16;
    //leader
    int ldrLen = XByteBuffer.toInt(buf.getBytesDirect(),offset);
    offset += 4;
    byte[] ldr = new byte[ldrLen];
    System.arraycopy(buf.getBytesDirect(),offset,ldr,0,ldrLen);
    leader = MemberImpl.getMember(ldr);
    offset += ldrLen;
    //source
    int srcLen = XByteBuffer.toInt(buf.getBytesDirect(),offset);
    offset += 4;
    byte[] src = new byte[srcLen];
    System.arraycopy(buf.getBytesDirect(),offset,src,0,srcLen);
    source = MemberImpl.getMember(src);
    offset += srcLen;
    //view
    int mbrCount = XByteBuffer.toInt(buf.getBytesDirect(),offset);
    offset += 4;
    view = new Member[mbrCount];
    for (int i=0; i<view.length; i++ ) {
        int mbrLen = XByteBuffer.toInt(buf.getBytesDirect(),offset);
        offset += 4;
        byte[] mbr = new byte[mbrLen];
        System.arraycopy(buf.getBytesDirect(), offset, mbr, 0, mbrLen);
        view[i] = MemberImpl.getMember(mbr);
        offset += mbrLen;
    }
    //id
    this.id = new UniqueId(buf.getBytesDirect(),offset,16);
    offset += 16;
    type = new byte[16];
    System.arraycopy(buf.getBytesDirect(), offset, type, 0, type.length);
    offset += 16;

}
 
Example #6
Source File: NonBlockingCoordinator.java    From Tomcat7.0.67 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 #7
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 #8
Source File: ChannelCoordinator.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void messageReceived(ChannelMessage msg) {
    if ( Logs.MESSAGES.isTraceEnabled() ) {
        Logs.MESSAGES.trace("ChannelCoordinator - Received msg:" + new UniqueId(msg.getUniqueId()) + " at " +new java.sql.Timestamp(System.currentTimeMillis())+ " from "+msg.getAddress().getName());
    }
    super.messageReceived(msg);
}
 
Example #9
Source File: ChannelCoordinator.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public void messageReceived(ChannelMessage msg) {
    if ( Logs.MESSAGES.isTraceEnabled() ) {
        Logs.MESSAGES.trace("ChannelCoordinator - Received msg:" + new UniqueId(msg.getUniqueId()) + " at " +new java.sql.Timestamp(System.currentTimeMillis())+ " from "+msg.getAddress().getName());
    }
    super.messageReceived(msg);
}
 
Example #10
Source File: ChannelCoordinator.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Send a message to one or more members in the cluster
 * @param destination Member[] - the destinations, null or zero length means all
 * @param msg ClusterMessage - the message to send
 * @param payload TBA
 */
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    if ( destination == null ) destination = membershipService.getMembers();
    if ((msg.getOptions()&Channel.SEND_OPTIONS_MULTICAST) == Channel.SEND_OPTIONS_MULTICAST) {
        membershipService.broadcast(msg);
    } else {
        clusterSender.sendMessage(msg,destination);
    }
    if ( Logs.MESSAGES.isTraceEnabled() ) {
        Logs.MESSAGES.trace("ChannelCoordinator - Sent msg:" + new UniqueId(msg.getUniqueId()) + " at " +new java.sql.Timestamp(System.currentTimeMillis())+ " to "+Arrays.toNameString(destination));
    }
}
 
Example #11
Source File: NonBlockingCoordinator.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public CoordinationMessage(MemberImpl leader,
                           MemberImpl source, 
                           MemberImpl[] view,
                           UniqueId id,
                           byte[] type) {
    this.buf = new XByteBuffer(4096,false);
    this.leader = leader;
    this.source = source;
    this.view = view;
    this.id = id;
    this.type = type;
    this.write();
}
 
Example #12
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public CoordinationMessage(MemberImpl leader,
                           MemberImpl source, 
                           MemberImpl[] view,
                           UniqueId id,
                           byte[] type) {
    this.buf = new XByteBuffer(4096,false);
    this.leader = leader;
    this.source = source;
    this.view = view;
    this.id = id;
    this.type = type;
    this.write();
}
 
Example #13
Source File: ChannelCoordinator.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Send a message to one or more members in the cluster
 * @param destination Member[] - the destinations, null or zero length means all
 * @param msg ClusterMessage - the message to send
 * @param payload TBA
 */
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    if ( destination == null ) destination = membershipService.getMembers();
    if ((msg.getOptions()&Channel.SEND_OPTIONS_MULTICAST) == Channel.SEND_OPTIONS_MULTICAST) {
        membershipService.broadcast(msg);
    } else {
        clusterSender.sendMessage(msg,destination);
    }
    if ( Logs.MESSAGES.isTraceEnabled() ) {
        Logs.MESSAGES.trace("ChannelCoordinator - Sent msg:" + new UniqueId(msg.getUniqueId()) + " at " +new java.sql.Timestamp(System.currentTimeMillis())+ " to "+Arrays.toNameString(destination));
    }
}
 
Example #14
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public void parse() {
    //header
    int offset = 16;
    //leader
    int ldrLen = XByteBuffer.toInt(buf.getBytesDirect(),offset);
    offset += 4;
    byte[] ldr = new byte[ldrLen];
    System.arraycopy(buf.getBytesDirect(),offset,ldr,0,ldrLen);
    leader = MemberImpl.getMember(ldr);
    offset += ldrLen;
    //source
    int srcLen = XByteBuffer.toInt(buf.getBytesDirect(),offset);
    offset += 4;
    byte[] src = new byte[srcLen];
    System.arraycopy(buf.getBytesDirect(),offset,src,0,srcLen);
    source = MemberImpl.getMember(src);
    offset += srcLen;
    //view
    int mbrCount = XByteBuffer.toInt(buf.getBytesDirect(),offset);
    offset += 4;
    view = new MemberImpl[mbrCount];
    for (int i=0; i<view.length; i++ ) {
        int mbrLen = XByteBuffer.toInt(buf.getBytesDirect(),offset);
        offset += 4;
        byte[] mbr = new byte[mbrLen];
        System.arraycopy(buf.getBytesDirect(), offset, mbr, 0, mbrLen);
        view[i] = MemberImpl.getMember(mbr);
        offset += mbrLen;
    }
    //id
    this.id = new UniqueId(buf.getBytesDirect(),offset,16);
    offset += 16;
    type = new byte[16];
    System.arraycopy(buf.getBytesDirect(), offset, type, 0, type.length);
    offset += 16;
    
}
 
Example #15
Source File: NonBlockingCoordinator.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public CoordinationMessage(Member leader,
                           Member source,
                           Member[] view,
                           UniqueId id,
                           byte[] type) {
    this.buf = new XByteBuffer(4096,false);
    this.leader = leader;
    this.source = source;
    this.view = view;
    this.id = id;
    this.type = type;
    this.write();
}
 
Example #16
Source File: NonBlockingCoordinator.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private CoordinationMessage createElectionMsg(Member local, Member[] others, Member leader) {
    Membership m = new Membership(local,AbsoluteOrder.comp,true);
    Arrays.fill(m,others);
    Member[] mbrs = m.getMembers();
    m.reset();
    CoordinationMessage msg = new CoordinationMessage(leader, local, mbrs,new UniqueId(UUIDGenerator.randomUUID(true)), COORD_REQUEST);
    return msg;
}
 
Example #17
Source File: NonBlockingCoordinator.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public void parse() {
    //header
    int offset = 16;
    //leader
    int ldrLen = XByteBuffer.toInt(buf.getBytesDirect(),offset);
    offset += 4;
    byte[] ldr = new byte[ldrLen];
    System.arraycopy(buf.getBytesDirect(),offset,ldr,0,ldrLen);
    leader = MemberImpl.getMember(ldr);
    offset += ldrLen;
    //source
    int srcLen = XByteBuffer.toInt(buf.getBytesDirect(),offset);
    offset += 4;
    byte[] src = new byte[srcLen];
    System.arraycopy(buf.getBytesDirect(),offset,src,0,srcLen);
    source = MemberImpl.getMember(src);
    offset += srcLen;
    //view
    int mbrCount = XByteBuffer.toInt(buf.getBytesDirect(),offset);
    offset += 4;
    view = new MemberImpl[mbrCount];
    for (int i=0; i<view.length; i++ ) {
        int mbrLen = XByteBuffer.toInt(buf.getBytesDirect(),offset);
        offset += 4;
        byte[] mbr = new byte[mbrLen];
        System.arraycopy(buf.getBytesDirect(), offset, mbr, 0, mbrLen);
        view[i] = MemberImpl.getMember(mbr);
        offset += mbrLen;
    }
    //id
    this.id = new UniqueId(buf.getBytesDirect(),offset,16);
    offset += 16;
    type = new byte[16];
    System.arraycopy(buf.getBytesDirect(), offset, type, 0, type.length);
    offset += 16;
    
}
 
Example #18
Source File: ChannelCoordinator.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void messageReceived(ChannelMessage msg) {
    if ( Logs.MESSAGES.isTraceEnabled() ) {
        Logs.MESSAGES.trace("ChannelCoordinator - Received msg:" +
                new UniqueId(msg.getUniqueId()) + " at " +
                new java.sql.Timestamp(System.currentTimeMillis()) + " from " +
                msg.getAddress().getName());
    }
    super.messageReceived(msg);
}
 
Example #19
Source File: Arrays.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
public static UniqueId getUniqudId(byte[] data) {
    return new UniqueId(data);
}
 
Example #20
Source File: NonBlockingCoordinator.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
public UniqueId getViewId() {
    return viewId;
}
 
Example #21
Source File: GroupChannel.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 *
 * @param destination Member[] - destination.length > 0
 * @param msg Serializable - the message to send
 * @param options int - sender options, options can trigger guarantee levels and different interceptors to
 * react to the message see class documentation for the <code>Channel</code> object.<br>
 * @param handler - callback object for error handling and completion notification, used when a message is
 * sent asynchronously using the <code>Channel.SEND_OPTIONS_ASYNCHRONOUS</code> flag enabled.
 * @return UniqueId - the unique Id that was assigned to this message
 * @throws ChannelException - if an error occurs processing the message
 * @see org.apache.catalina.tribes.Channel
 */
@Override
public UniqueId send(Member[] destination, Serializable msg, int options, ErrorHandler handler) throws ChannelException {
    if ( msg == null ) throw new ChannelException("Cant send a NULL message");
    XByteBuffer buffer = null;
    try {
        if ( destination == null || destination.length == 0) throw new ChannelException("No destination given");
        ChannelData data = new ChannelData(true);//generates a unique Id
        data.setAddress(getLocalMember(false));
        data.setTimestamp(System.currentTimeMillis());
        byte[] b = null;
        if ( msg instanceof ByteMessage ){
            b = ((ByteMessage)msg).getMessage();
            options = options | SEND_OPTIONS_BYTE_MESSAGE;
        } else {
            b = XByteBuffer.serialize(msg);
            options = options & (~SEND_OPTIONS_BYTE_MESSAGE);
        }
        data.setOptions(options);
        //XByteBuffer buffer = new XByteBuffer(b.length+128,false);
        buffer = BufferPool.getBufferPool().getBuffer(b.length+128, false);
        buffer.append(b,0,b.length);
        data.setMessage(buffer);
        InterceptorPayload payload = null;
        if ( handler != null ) {
            payload = new InterceptorPayload();
            payload.setErrorHandler(handler);
        }
        getFirstInterceptor().sendMessage(destination, data, payload);
        if ( Logs.MESSAGES.isTraceEnabled() ) {
            Logs.MESSAGES.trace("GroupChannel - Sent msg:" + new UniqueId(data.getUniqueId()) + " at " +new java.sql.Timestamp(System.currentTimeMillis())+ " to "+Arrays.toNameString(destination));
            Logs.MESSAGES.trace("GroupChannel - Send Message:" + new UniqueId(data.getUniqueId()) + " is " +msg);
        }

        return new UniqueId(data.getUniqueId());
    }catch ( Exception x ) {
        if ( x instanceof ChannelException ) throw (ChannelException)x;
        throw new ChannelException(x);
    } finally {
        if ( buffer != null ) BufferPool.getBufferPool().returnBuffer(buffer);
    }
}
 
Example #22
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
protected void viewChange(UniqueId viewId, Member[] view) {
    //invoke any listeners
}
 
Example #23
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public UniqueId getViewId() {
    return viewId;
}
 
Example #24
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public UniqueId getId() {
    if ( id == null ) parse();
    return id;
}
 
Example #25
Source File: TwoPhaseCommitInterceptor.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public MapEntry(ChannelMessage msg, UniqueId id, long timestamp) {
    this.msg = msg;
    this.id = id;
    this.timestamp = timestamp;
}
 
Example #26
Source File: Arrays.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public static UniqueId getUniqudId(ChannelMessage msg) {
    return new UniqueId(msg.getUniqueId());
}
 
Example #27
Source File: Arrays.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public static UniqueId getUniqudId(byte[] data) {
    return new UniqueId(data);
}
 
Example #28
Source File: Arrays.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
public static UniqueId getUniqudId(ChannelMessage msg) {
    return new UniqueId(msg.getUniqueId());
}
 
Example #29
Source File: TwoPhaseCommitInterceptor.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
public MapEntry(ChannelMessage msg, UniqueId id, long timestamp) {
    this.msg = msg;
    this.id = id;
    this.timestamp = timestamp;
}
 
Example #30
Source File: NonBlockingCoordinator.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
public UniqueId getId() {
    if ( id == null ) parse();
    return id;
}