001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.catalina.tribes.group;
019:
020: import java.io.ObjectInput;
021: import java.io.Serializable;
022: import java.io.Externalizable;
023: import java.io.IOException;
024: import java.io.ObjectOutput;
025: import org.apache.catalina.tribes.util.Arrays;
026:
027: /**
028: * <p>Title: </p>
029: *
030: * <p>Description: </p>
031: *
032: * <p>Company: </p>
033: *
034: * @author not attributable
035: * @version 1.0
036: */
037: public class RpcMessage implements Externalizable {
038:
039: protected Serializable message;
040: protected byte[] uuid;
041: protected byte[] rpcId;
042: protected boolean reply = false;
043:
044: public RpcMessage() {
045: //for serialization
046: }
047:
048: public RpcMessage(byte[] rpcId, byte[] uuid, Serializable message) {
049: this .rpcId = rpcId;
050: this .uuid = uuid;
051: this .message = message;
052: }
053:
054: public void readExternal(ObjectInput in) throws IOException,
055: ClassNotFoundException {
056: reply = in.readBoolean();
057: int length = in.readInt();
058: uuid = new byte[length];
059: in.read(uuid, 0, length);
060: length = in.readInt();
061: rpcId = new byte[length];
062: in.read(rpcId, 0, length);
063: message = (Serializable) in.readObject();
064: }
065:
066: public void writeExternal(ObjectOutput out) throws IOException {
067: out.writeBoolean(reply);
068: out.writeInt(uuid.length);
069: out.write(uuid, 0, uuid.length);
070: out.writeInt(rpcId.length);
071: out.write(rpcId, 0, rpcId.length);
072: out.writeObject(message);
073: }
074:
075: public String toString() {
076: StringBuffer buf = new StringBuffer("RpcMessage[");
077: buf.append(super .toString());
078: buf.append("] rpcId=");
079: buf.append(Arrays.toString(rpcId));
080: buf.append("; uuid=");
081: buf.append(Arrays.toString(uuid));
082: buf.append("; msg=");
083: buf.append(message);
084: return buf.toString();
085: }
086:
087: public static class NoRpcChannelReply extends RpcMessage {
088: public NoRpcChannelReply() {
089:
090: }
091:
092: public NoRpcChannelReply(byte[] rpcid, byte[] uuid) {
093: super (rpcid, uuid, null);
094: reply = true;
095: }
096:
097: public void readExternal(ObjectInput in) throws IOException,
098: ClassNotFoundException {
099: reply = true;
100: int length = in.readInt();
101: uuid = new byte[length];
102: in.read(uuid, 0, length);
103: length = in.readInt();
104: rpcId = new byte[length];
105: in.read(rpcId, 0, length);
106: }
107:
108: public void writeExternal(ObjectOutput out) throws IOException {
109: out.writeInt(uuid.length);
110: out.write(uuid, 0, uuid.length);
111: out.writeInt(rpcId.length);
112: out.write(rpcId, 0, rpcId.length);
113: }
114: }
115:
116: }
|