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 CMCRequest extends CMCMessage{ 68 69 private String commandName; 70 private CMCRole actingRole; 71 72 75 public byte getType() { 76 return CMCConstance.TYPE_REQUEST; 77 } 78 79 82 public CMCRole getActingRole() { 83 return actingRole; 84 } 85 86 89 public void setActingRole(CMCRole actingRole) { 90 this.actingRole = actingRole; 91 } 92 93 96 public String getCommandName() { 97 return commandName; 98 } 99 100 103 public void setCommandName(String commandName) { 104 this.commandName = commandName; 105 } 106 107 110 public String getByteableName() { 111 112 return "org.mr.core.cmc.CMCRequest"; 113 } 114 115 118 public void toBytes(ByteableOutputStream out) throws IOException { 119 out.writeLong(getId()); 120 out.writeByteable(getParams()); 121 out.writeByte(actingRole.getRoles()); 123 out.writeASCIIString(commandName); 124 125 126 127 128 } 129 130 133 public Byteable createInstance(ByteableInputStream in) throws IOException { 134 CMCRequest result = new CMCRequest(); 135 result.setId(in.readLong()); 136 result.setParams((ByteableMap)in.readByteable()); 137 result.setActingRole(new CMCRole(in.readByte())); 138 result.setCommandName(in.readASCIIString()); 139 return result; 140 141 } 142 143 146 public void registerToByteableRegistry() { 147 ByteableRegistry.registerByteableFactory(getByteableName() , this); 148 } 149 150 public static void register(){ 151 CMCRequest instance = new CMCRequest(); 152 instance.registerToByteableRegistry(); 153 } 154 155 public String toString(){ 156 return "CMCRequest: commandName = "+commandName+" "+super.toString(); 157 } 158 159 } 160 | Popular Tags |