001 // Copyright 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.hivemind.internal.ser;
016
017 import java.io.Externalizable;
018 import java.io.IOException;
019 import java.io.ObjectInput;
020 import java.io.ObjectOutput;
021
022 import org.apache.hivemind.util.Defense;
023
024 /**
025 * Instance used to replace actual service (proxies) during serialization. Note that this represents
026 * a back-door into HiveMind's {@link org.apache.hivemind.internal.RegistryInfrastructure}, which
027 * is less than ideal, and should not be used by end-user code!
028 *
029 * @author Howard M. Lewis Ship
030 * @since 1.1
031 */
032 public class ServiceToken implements Externalizable
033 {
034 private static final long serialVersionUID = 1L;
035 private String _serviceId;
036
037 // Needed for Externalizable.
038
039 public ServiceToken()
040 {
041 }
042
043 public ServiceToken(String serviceId)
044 {
045 Defense.notNull(serviceId, "serviceId");
046
047 _serviceId = serviceId;
048 }
049
050 public String getServiceId()
051 {
052 return _serviceId;
053 }
054
055 public void writeExternal(ObjectOutput out) throws IOException
056 {
057 out.writeUTF(_serviceId);
058 }
059
060 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
061 {
062 _serviceId = in.readUTF();
063 }
064
065 Object readResolve()
066 {
067 return ServiceSerializationHelper.getServiceSerializationSupport()
068 .getServiceFromToken(this);
069 }
070 }