1 22 package org.jboss.invocation.pooled.interfaces; 23 24 import org.jboss.invocation.Invocation; 25 import org.jboss.invocation.InvocationType; 26 import org.jboss.invocation.MarshalledInvocation; 27 import org.jboss.invocation.MarshalledValue; 28 29 import javax.transaction.Transaction ; 30 import java.io.IOException ; 31 import java.lang.reflect.Method ; 32 import java.security.Principal ; 33 import java.util.HashMap ; 34 import java.util.Iterator ; 35 36 49 public class PooledMarshalledInvocation 50 extends MarshalledInvocation 51 implements java.io.Externalizable 52 { 53 55 56 static final long serialVersionUID = -728630295444149842L; 57 58 private transient Transaction tx; 59 private transient Object credential; 60 private transient Principal principal; 61 private transient Object enterpriseContext; 62 private transient Object id; 63 private transient PooledMarshalledValue pooledMarshalledArgs; 64 65 66 public PooledMarshalledInvocation() 68 { 69 } 71 72 public PooledMarshalledInvocation(Invocation invocation) 73 { 74 this.payload = invocation.payload; 75 this.as_is_payload = invocation.as_is_payload; 76 this.method = invocation.getMethod(); 77 this.objectName = invocation.getObjectName(); 78 this.args = invocation.getArguments(); 79 this.invocationType = invocation.getType(); 80 } 81 82 83 95 public PooledMarshalledInvocation( 96 Object id, 97 Method m, 98 Object [] args, 99 Transaction tx, 100 Principal identity, 101 Object credential) 102 { 103 super(id, m, args, tx, identity, credential); 104 } 105 107 108 109 public Object getEnterpriseContext() 110 { 111 return enterpriseContext; 112 } 113 114 public void setEnterpriseContext(Object enterpriseContext) 115 { 116 this.enterpriseContext = enterpriseContext; 117 } 118 119 public Object getId() 120 { 121 if (id == null) id = super.getId(); 122 return id; 123 } 124 125 public void setId(Object id) 126 { 127 super.setId(id); 128 this.id = id; 129 } 130 131 public void setTransaction(Transaction tx) 132 { 133 super.setTransaction(tx); 134 this.tx = tx; 135 } 136 137 public Transaction getTransaction() 138 { 139 if (tx == null) tx = super.getTransaction(); 140 return this.tx; 141 } 142 143 public Object getCredential() 144 { 145 if (credential == null) credential = super.getCredential(); 146 return credential; 147 } 148 149 public void setCredential(Object credential) 150 { 151 super.setCredential(credential); 152 this.credential = credential; 153 } 154 155 public Principal getPrincipal() 156 { 157 if (principal == null) principal = super.getPrincipal(); 158 return principal; 159 } 160 161 public void setPrincipal(Principal principal) 162 { 163 super.setPrincipal(principal); 164 this.principal = principal; 165 } 166 167 168 public Object [] getArguments() 169 { 170 if (this.args == null) 171 { 172 try 173 { 174 this.args = (Object []) pooledMarshalledArgs.get(); 175 } 176 catch (Exception e) 177 { 178 e.printStackTrace(); 179 } 180 } 181 return args; 182 } 183 184 public void writeExternal(java.io.ObjectOutput out) 186 throws IOException 187 { 188 out.writeObject(invocationType); 189 out.writeObject(tpc); 192 193 long methodHash = calculateHash(this.method); 194 out.writeLong(methodHash); 195 196 out.writeInt(((Integer )this.objectName).intValue()); 197 out.writeObject(new PooledMarshalledValue(this.args)); 198 199 200 if (payload == null) 209 out.writeInt(0); 210 else 211 { 212 out.writeInt(payload.size()); 213 Iterator keys = payload.keySet().iterator(); 214 while (keys.hasNext()) 215 { 216 Object currentKey = keys.next(); 217 218 221 out.writeObject(currentKey); 222 out.writeObject(new MarshalledValue(payload.get(currentKey))); 223 } 224 } 225 226 if (as_is_payload == null) 229 out.writeInt(0); 230 else 231 { 232 out.writeInt(as_is_payload.size()); 233 234 Iterator keys = as_is_payload.keySet().iterator(); 235 while (keys.hasNext()) 236 { 237 Object currentKey = keys.next(); 238 out.writeObject(currentKey); 239 out.writeObject(as_is_payload.get(currentKey)); 240 } 241 } 242 } 243 244 public void readExternal(java.io.ObjectInput in) 245 throws IOException , ClassNotFoundException 246 { 247 invocationType = (InvocationType)in.readObject(); 248 tpc = in.readObject(); 249 this.methodHash = in.readLong(); 250 251 this.objectName = new Integer (in.readInt()); 252 253 pooledMarshalledArgs = (PooledMarshalledValue) in.readObject(); 254 255 int payloadSize = in.readInt(); 256 if (payloadSize > 0) 257 { 258 payload = new HashMap (); 259 for (int i = 0; i < payloadSize; i++) 260 { 261 Object key = in.readObject(); 262 Object value = in.readObject(); 263 payload.put(key, value); 264 } 265 } 266 267 int as_is_payloadSize = in.readInt(); 268 if (as_is_payloadSize > 0) 269 { 270 as_is_payload = new HashMap (); 271 for (int i = 0; i < as_is_payloadSize; i++) 272 { 273 Object key = in.readObject(); 274 Object value = in.readObject(); 275 as_is_payload.put(key, value); 276 } 277 } 278 } 279 } 280 | Popular Tags |