1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.river.phoenix.dl;
20
21 import java.io.IOException;
22 import java.io.Serializable;
23 import java.rmi.Remote;
24 import java.rmi.RemoteException;
25 import java.rmi.UnmarshalException;
26 import java.rmi.activation.ActivationException;
27 import java.rmi.activation.ActivationID;
28 import java.rmi.server.UID;
29 import java.security.AccessController;
30 import java.security.PrivilegedAction;
31 import net.jini.export.ProxyAccessor;
32 import org.apache.river.api.io.AtomicSerial;
33 import org.apache.river.api.io.AtomicSerial.GetArg;
34 import org.apache.river.proxy.MarshalledWrapper;
35
36
37
38
39
40
41 public class AID extends ActivationID {
42 private static final long serialVersionUID = 681896091039721074L;
43
44 protected final Activator activator;
45 protected final UID uid;
46
47 @AtomicSerial
48 static final class State implements Serializable, ProxyAccessor {
49 private static final long serialVersionUID = 4479839553358267720L;
50
51 private final Activator activator;
52 private final UID uid;
53
54 State(Activator activator, UID uid) {
55 this.activator = activator;
56 this.uid = uid;
57 }
58
59 public State(GetArg arg) throws IOException{
60 this(arg.get("activator", null, Activator.class),
61 arg.get("uid", null, UID.class));
62 }
63
64 private Object readResolve() {
65 return new AID(activator, uid);
66 }
67
68 public Object getProxy() {
69 return activator;
70 }
71 }
72
73 public AID(Activator activator, UID uid) {
74 super(null);
75 this.activator = activator;
76 this.uid = uid;
77 }
78
79
80
81
82 @Override
83 public Remote activate(boolean force)
84 throws ActivationException, RemoteException
85 {
86 try {
87 MarshalledWrapper marshalledProxy =
88 activator.activate(this, force);
89 ClassLoader loader = classLoader();
90 return (Remote) marshalledProxy.get(loader, loader);
91 } catch (RemoteException e) {
92 throw e;
93 } catch (java.io.IOException e) {
94 throw new UnmarshalException("activation failed", e);
95 } catch (java.lang.ClassNotFoundException e) {
96 throw new UnmarshalException("activation failed", e);
97 }
98
99 }
100
101 private ClassLoader classLoader(){
102 return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>(){
103
104 public ClassLoader run() {
105 return AID.class.getClassLoader();
106 }
107
108 });
109 }
110
111 public UID getUID() {
112 return uid;
113 }
114
115 @Override
116 public int hashCode() {
117 return uid.hashCode();
118 }
119
120 @Override
121 public boolean equals(Object obj) {
122 if (obj != null && obj.getClass() == getClass()) {
123 AID id = (AID) obj;
124 return (uid.equals(id.uid) && activator.equals(id.activator));
125 }
126 return false;
127 }
128
129 private Object writeReplace() {
130 return new State(activator, uid);
131 }
132 }