1 46 52 package org.mr.core.cmc; 53 54 import java.io.IOException ; 55 56 import org.mr.core.util.byteable.Byteable; 57 import org.mr.core.util.byteable.ByteableInputStream; 58 import org.mr.core.util.byteable.ByteableMap; 59 import org.mr.core.util.byteable.ByteableOutputStream; 60 import org.mr.core.util.byteable.ByteableRegistry; 61 62 67 public class CMCResponse extends CMCMessage{ 68 69 long responseToId; 70 byte responseCode; 71 72 75 public byte getType() { 76 return CMCConstance.TYPE_RESPONSE; 77 } 78 79 82 public byte getResponseCode() { 83 return responseCode; 84 } 85 86 89 public void setResponseCode(byte responseCode) { 90 this.responseCode = responseCode; 91 } 92 93 96 public long getResponseToId() { 97 return responseToId; 98 } 99 100 103 public void setResponseToId(long responseToId) { 104 this.responseToId = responseToId; 105 } 106 107 public String toString(){ 108 StringBuffer buff = new StringBuffer (); 109 buff.append(" Response to id "); 110 buff.append(responseToId ); 111 buff.append(" Response code "); 112 buff.append(responseCode); 113 buff.append(" Result: \r\n"); 114 buff.append(super.toString()); 115 return buff.toString(); 116 } 117 118 121 public String getByteableName() { 122 123 return "org.mr.core.cmc.CMCResponse"; 124 } 125 126 129 public void toBytes(ByteableOutputStream out) throws IOException { 130 out.writeLong(getId()); 131 out.writeByteable(getParams()); 132 out.writeLong(responseToId); 133 out.writeByte(responseCode); 134 135 136 137 138 } 139 140 143 public Byteable createInstance(ByteableInputStream in) throws IOException { 144 CMCResponse result = new CMCResponse(); 145 result.setId(in.readLong()); 146 result.setParams((ByteableMap)in.readByteable()); 147 result.setResponseToId(in.readLong()); 148 result.setResponseCode(in.readByte()); 149 return result; 150 151 } 152 153 156 public void registerToByteableRegistry() { 157 ByteableRegistry.registerByteableFactory(getByteableName() , this); 158 } 159 160 public static void register(){ 161 CMCResponse instance = new CMCResponse(); 162 instance.registerToByteableRegistry(); 163 } 164 165 166 } 167 | Popular Tags |