|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ServiceToken.java | - | 100% | 100% | 100% |
|
1 | // Copyright 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | package org.apache.hivemind.internal.ser; | |
16 | ||
17 | import java.io.Externalizable; | |
18 | import java.io.IOException; | |
19 | import java.io.ObjectInput; | |
20 | import java.io.ObjectOutput; | |
21 | ||
22 | import org.apache.hivemind.util.Defense; | |
23 | ||
24 | /** | |
25 | * Instance used to replace actual service (proxies) during serialization. Note that this represents | |
26 | * a back-door into HiveMind's {@link org.apache.hivemind.internal.RegistryInfrastructure}, which | |
27 | * is less than ideal, and should not be used by end-user code! | |
28 | * | |
29 | * @author Howard M. Lewis Ship | |
30 | * @since 1.1 | |
31 | */ | |
32 | public class ServiceToken implements Externalizable | |
33 | { | |
34 | private static final long serialVersionUID = 1L; | |
35 | private String _serviceId; | |
36 | ||
37 | // Needed for Externalizable. | |
38 | ||
39 | 1 | public ServiceToken() |
40 | { | |
41 | } | |
42 | ||
43 | 1 | public ServiceToken(String serviceId) |
44 | { | |
45 | 1 | Defense.notNull(serviceId, "serviceId"); |
46 | ||
47 | 1 | _serviceId = serviceId; |
48 | } | |
49 | ||
50 | 1 | public String getServiceId() |
51 | { | |
52 | 1 | return _serviceId; |
53 | } | |
54 | ||
55 | 1 | public void writeExternal(ObjectOutput out) throws IOException |
56 | { | |
57 | 1 | out.writeUTF(_serviceId); |
58 | } | |
59 | ||
60 | 1 | public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException |
61 | { | |
62 | 1 | _serviceId = in.readUTF(); |
63 | } | |
64 | ||
65 | 1 | Object readResolve() |
66 | { | |
67 | 1 | return ServiceSerializationHelper.getServiceSerializationSupport() |
68 | .getServiceFromToken(this); | |
69 | } | |
70 | } |
|