/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/ package org.apache.catalina.tribes.io;
/** * The <code>ChannelData</code> object is used to transfer a message through the * channel interceptor stack and eventually out on a transport to be sent * to another node. While the message is being processed by the different * interceptors, the message data can be manipulated as each interceptor seems appropriate. * @author Peter Rossbach
*/ publicclass ChannelData implements ChannelMessage { privatestaticfinallong serialVersionUID = 1L;
publicstaticfinal ChannelData[] EMPTY_DATA_ARRAY = new ChannelData[0];
/** * The options this message was sent with
*/ privateint options = 0 ; /** * The message data, stored in a dynamic buffer
*/ private XByteBuffer message ; /** * The timestamp that goes with this message
*/ privatelong timestamp ; /** * A unique message id
*/ privatebyte[] uniqueId ; /** * The source or reply-to address for this message
*/ private Member address;
/** * Creates an empty channel data with a new unique Id * @see #ChannelData(boolean)
*/ public ChannelData() { this(true);
}
/** * Create an empty channel data object * @param generateUUID boolean - if true, a unique Id will be generated
*/ public ChannelData(boolean generateUUID) { if ( generateUUID ) {
generateUUID();
}
}
/** * Creates a new channel data object with data * @param uniqueId - unique message id * @param message - message data * @param timestamp - message timestamp
*/ public ChannelData(byte[] uniqueId, XByteBuffer message, long timestamp) { this.uniqueId = uniqueId; this.message = message; this.timestamp = timestamp;
}
/** * Compares to ChannelData objects, only compares on getUniqueId().equals(o.getUniqueId()) * @param o Object * @return boolean
*/
@Override publicboolean equals(Object o) { if ( o instanceof ChannelData ) { return Arrays.equals(getUniqueId(),((ChannelData)o).getUniqueId());
} else { returnfalse;
}
}
/** * Create a shallow clone, only the data gets recreated * @return ClusterData
*/
@Override public ChannelData clone() {
ChannelData clone; try {
clone = (ChannelData) super.clone();
} catch (CloneNotSupportedException e) { // Cannot happen thrownew AssertionError();
} if (this.message != null) {
clone.message = new XByteBuffer(this.message.getBytesDirect(),false);
} return clone;
}
/** * Complete clone * @return ClusterData
*/
@Override public Object deepclone() { byte[] d = this.getDataPackage(); return getDataFromPackage(d);
}
/** * Utility method, returns true if the options flag indicates that an ack * is to be sent after the message has been received and processed * @param options int - the options for the message * @return boolean * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_USE_ACK * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_SYNCHRONIZED_ACK
*/ publicstaticboolean sendAckSync(int options) { return ( (Channel.SEND_OPTIONS_USE_ACK & options) == Channel.SEND_OPTIONS_USE_ACK) &&
( (Channel.SEND_OPTIONS_SYNCHRONIZED_ACK & options) == Channel.SEND_OPTIONS_SYNCHRONIZED_ACK);
}
/** * Utility method, returns true if the options flag indicates that an ack * is to be sent after the message has been received but not yet processed * @param options int - the options for the message * @return boolean * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_USE_ACK * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_SYNCHRONIZED_ACK
*/ publicstaticboolean sendAckAsync(int options) { return ( (Channel.SEND_OPTIONS_USE_ACK & options) == Channel.SEND_OPTIONS_USE_ACK) &&
( (Channel.SEND_OPTIONS_SYNCHRONIZED_ACK & options) != Channel.SEND_OPTIONS_SYNCHRONIZED_ACK);
}
@Override public String toString() {
StringBuilder buf = new StringBuilder();
buf.append("ClusterData[src=");
buf.append(getAddress()).append("; id=");
buf.append(bToS(getUniqueId())).append("; sent=");
buf.append(new Timestamp(this.getTimestamp()).toString()).append(']'); return buf.toString();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.