Add methods to Endpoint/EndpointReference to set the ExtensionPointRegistry so that deserialized object can be resolved
Make the EndpointSerializer a declared utility git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@784270 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c2b73c42cf
commit
667940fec1
11 changed files with 253 additions and 97 deletions
|
@ -21,6 +21,7 @@ package org.apache.tuscany.sca.assembly;
|
|||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
|
||||
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
|
||||
import org.apache.tuscany.sca.policy.PolicySubject;
|
||||
|
||||
|
@ -118,4 +119,12 @@ public interface Endpoint extends Base, PolicySubject, Cloneable, Serializable {
|
|||
*/
|
||||
List<EndpointReference> getCallbackEndpointReferences();
|
||||
|
||||
/**
|
||||
* Set the extension point registry against the endpoint after it is deserialized as
|
||||
* the registry needs to be re-attached
|
||||
*
|
||||
* @param registry
|
||||
*/
|
||||
void setExtensionPointRegistry(ExtensionPointRegistry registry);
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.tuscany.sca.assembly;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
|
||||
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
|
||||
import org.apache.tuscany.sca.policy.PolicySubject;
|
||||
|
||||
|
@ -138,4 +139,12 @@ public interface EndpointReference extends Base, PolicySubject, Cloneable, Seria
|
|||
* @param callbackEndpoint the reference callback endpoint
|
||||
*/
|
||||
void setCallbackEndpoint(Endpoint callbackEndpoint);
|
||||
|
||||
/**
|
||||
* Set the extension point registry against the endpoint after it is deserialized as
|
||||
* the registry needs to be re-attached
|
||||
*
|
||||
* @param registry
|
||||
*/
|
||||
void setExtensionPointRegistry(ExtensionPointRegistry registry);
|
||||
}
|
||||
|
|
|
@ -182,4 +182,8 @@ public class EndpointImpl implements Endpoint {
|
|||
protected void reset() {
|
||||
this.uri = null;
|
||||
}
|
||||
|
||||
public void setExtensionPointRegistry(ExtensionPointRegistry registry) {
|
||||
this.registry = registry;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.apache.tuscany.sca.policy.PolicySubject;
|
|||
* @version $Rev$ $Date$
|
||||
*/
|
||||
public class EndpointReferenceImpl implements EndpointReference {
|
||||
private static final long serialVersionUID = 8838066441709300972L;
|
||||
protected ExtensionPointRegistry registry;
|
||||
protected boolean unresolved = true;
|
||||
protected String uri;
|
||||
|
@ -80,53 +81,62 @@ public class EndpointReferenceImpl implements EndpointReference {
|
|||
}
|
||||
|
||||
public Component getComponent() {
|
||||
resolve();
|
||||
return component;
|
||||
}
|
||||
|
||||
public void setComponent(Component component) {
|
||||
this.component = component;
|
||||
this.uri = null;
|
||||
reset();
|
||||
}
|
||||
|
||||
public ComponentReference getReference() {
|
||||
resolve();
|
||||
return reference;
|
||||
}
|
||||
|
||||
public void setReference(ComponentReference reference) {
|
||||
this.reference = reference;
|
||||
this.uri = null;
|
||||
reset();
|
||||
}
|
||||
|
||||
public Binding getBinding() {
|
||||
resolve();
|
||||
return binding;
|
||||
}
|
||||
|
||||
public void setBinding(Binding binding) {
|
||||
this.binding = binding;
|
||||
this.uri = null;
|
||||
reset();
|
||||
}
|
||||
|
||||
public Endpoint getTargetEndpoint() {
|
||||
resolve();
|
||||
return targetEndpoint;
|
||||
}
|
||||
|
||||
public void setTargetEndpoint(Endpoint targetEndpoint) {
|
||||
this.targetEndpoint = targetEndpoint;
|
||||
reset();
|
||||
}
|
||||
|
||||
public InterfaceContract getInterfaceContract() {
|
||||
resolve();
|
||||
return interfaceContract;
|
||||
}
|
||||
|
||||
public void setInterfaceContract(InterfaceContract interfaceContract) {
|
||||
this.interfaceContract = interfaceContract;
|
||||
reset();
|
||||
}
|
||||
|
||||
public List<PolicySet> getPolicySets() {
|
||||
resolve();
|
||||
return policySets;
|
||||
}
|
||||
|
||||
public List<Intent> getRequiredIntents() {
|
||||
resolve();
|
||||
return requiredIntents;
|
||||
}
|
||||
|
||||
|
@ -142,11 +152,13 @@ public class EndpointReferenceImpl implements EndpointReference {
|
|||
}
|
||||
|
||||
public Endpoint getCallbackEndpoint() {
|
||||
resolve();
|
||||
return callbackEndpoint;
|
||||
}
|
||||
|
||||
public void setCallbackEndpoint(Endpoint callbackEndpoint) {
|
||||
this.callbackEndpoint = callbackEndpoint;
|
||||
reset();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@ -187,4 +199,15 @@ public class EndpointReferenceImpl implements EndpointReference {
|
|||
public void setURI(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
protected void resolve() {
|
||||
}
|
||||
|
||||
protected void reset() {
|
||||
this.uri = null;
|
||||
}
|
||||
|
||||
public void setExtensionPointRegistry(ExtensionPointRegistry registry) {
|
||||
this.registry = registry;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,15 +6,15 @@
|
|||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tuscany.sca.runtime;
|
||||
|
@ -29,54 +29,26 @@ import org.apache.tuscany.sca.invocation.InvocationChain;
|
|||
import org.apache.tuscany.sca.invocation.Message;
|
||||
|
||||
/**
|
||||
* The runtime wire interface that connects a component reference to a
|
||||
* The runtime wire interface that connects a component reference to a
|
||||
* component service (or an external service) over the selected binding
|
||||
*
|
||||
*
|
||||
* @version $Rev$ $Date$
|
||||
*/
|
||||
public interface RuntimeWire extends Cloneable {
|
||||
|
||||
|
||||
// =================================================================
|
||||
// TODO - EPR - remove the following three methods when we have
|
||||
// changes the rest of the instructure over to using EndpointReference2
|
||||
// and EndpointReference2 throughout
|
||||
/**
|
||||
* Get the source of the wire
|
||||
*
|
||||
* @return The end point reference of the source
|
||||
*/
|
||||
// EndpointReference getSource();
|
||||
|
||||
/**
|
||||
* Get the target of the wire
|
||||
*
|
||||
* @return The end point reference of the target
|
||||
*/
|
||||
// EndpointReference getTarget();
|
||||
|
||||
/**
|
||||
* Rebind the runtime wire with the given target
|
||||
* @param target The target endpoint reference
|
||||
*/
|
||||
// void setTarget(EndpointReference target);
|
||||
|
||||
//==================================================================
|
||||
|
||||
/**
|
||||
* return the endpoint reference that configured this wire
|
||||
*
|
||||
* @return the endpoint reference that configured this wire
|
||||
*
|
||||
* @return the endpoint reference that configured this wire
|
||||
*/
|
||||
EndpointReference getEndpointReference();
|
||||
|
||||
|
||||
/**
|
||||
* return the endpoint that configured this wire
|
||||
*
|
||||
* @return the endpoint that configured this wire
|
||||
*
|
||||
* @return the endpoint that configured this wire
|
||||
*/
|
||||
Endpoint getEndpoint();
|
||||
|
||||
Endpoint getEndpoint();
|
||||
|
||||
/**
|
||||
* Force the invocation chains to be rebuilt
|
||||
*/
|
||||
|
@ -85,35 +57,35 @@ public interface RuntimeWire extends Cloneable {
|
|||
/**
|
||||
* Returns the invocation chains for service operations associated with the
|
||||
* wire
|
||||
*
|
||||
*
|
||||
* @return the invocation chains for service operations associated with the
|
||||
* wire
|
||||
*/
|
||||
List<InvocationChain> getInvocationChains();
|
||||
|
||||
|
||||
/**
|
||||
* Lookup the invocation chain by operation
|
||||
* @param operation The operation
|
||||
* @return The invocation chain for the given operation
|
||||
*/
|
||||
InvocationChain getInvocationChain(Operation operation);
|
||||
|
||||
|
||||
/**
|
||||
* Get the invocation chain for the binding-specific handling
|
||||
* @return
|
||||
*/
|
||||
InvocationChain getBindingInvocationChain();
|
||||
|
||||
|
||||
/**
|
||||
* This invoke method assumes that the binding invocation chain is in force
|
||||
* and that there will be an operation selector element there to
|
||||
* determine which operation to call
|
||||
* determine which operation to call
|
||||
* @param msg The message
|
||||
* @return The result
|
||||
* @throws InvocationTargetException
|
||||
*/
|
||||
Object invoke(Message msg) throws InvocationTargetException;
|
||||
|
||||
Object invoke(Message msg) throws InvocationTargetException;
|
||||
|
||||
/**
|
||||
* Invoke an operation with given arguments
|
||||
* @param operation The operation
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.apache.tuscany.sca.core.assembly;
|
||||
|
||||
import org.apache.tuscany.sca.assembly.AssemblyFactory;
|
||||
|
||||
import org.apache.tuscany.sca.assembly.Component;
|
||||
import org.apache.tuscany.sca.assembly.ComponentReference;
|
||||
import org.apache.tuscany.sca.assembly.ComponentService;
|
||||
|
@ -28,10 +27,11 @@ import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
|
|||
import org.apache.tuscany.sca.assembly.Endpoint;
|
||||
import org.apache.tuscany.sca.assembly.EndpointReference;
|
||||
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
|
||||
import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointImpl;
|
||||
import org.apache.tuscany.sca.core.assembly.impl.RuntimeComponentImpl;
|
||||
import org.apache.tuscany.sca.core.assembly.impl.RuntimeComponentReferenceImpl;
|
||||
import org.apache.tuscany.sca.core.assembly.impl.RuntimeComponentServiceImpl;
|
||||
import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointImpl;
|
||||
import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointReferenceImpl;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -59,25 +59,6 @@ public class RuntimeAssemblyFactory extends DefaultAssemblyFactory implements As
|
|||
return new RuntimeComponentServiceImpl();
|
||||
}
|
||||
|
||||
/* TODO - EPR - remove now
|
||||
// FIXME: [rfeng] We need to find a more consistent story to deal with EPR, EP and CallableReference
|
||||
public EndpointReference createEndpointReference(String uri) {
|
||||
return new EndpointReferenceImpl(uri);
|
||||
}
|
||||
|
||||
public EndpointReference createEndpointReference(RuntimeComponent component,
|
||||
Contract contract,
|
||||
Binding binding,
|
||||
InterfaceContract interfaceContract) {
|
||||
return new EndpointReferenceImpl(component, contract, binding, interfaceContract);
|
||||
}
|
||||
|
||||
|
||||
public ReferenceParameters createReferenceParameters() {
|
||||
return new ReferenceParametersImpl();
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Endpoint createEndpoint() {
|
||||
// Create an instance of EndpointImpl that can be serialized/deserialized using the Tuscany
|
||||
|
@ -87,7 +68,7 @@ public class RuntimeAssemblyFactory extends DefaultAssemblyFactory implements As
|
|||
|
||||
@Override
|
||||
public EndpointReference createEndpointReference() {
|
||||
return super.createEndpointReference();
|
||||
return new RuntimeEndpointReferenceImpl(registry);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,17 +26,14 @@ import java.io.ObjectOutput;
|
|||
|
||||
import org.apache.tuscany.sca.assembly.impl.EndpointImpl;
|
||||
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
|
||||
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
|
||||
import org.apache.tuscany.sca.core.assembly.EndpointSerializer;
|
||||
|
||||
/**
|
||||
* Runtime model for Endpoint that supports java serialization
|
||||
*/
|
||||
public class RuntimeEndpointImpl extends EndpointImpl implements Externalizable {
|
||||
/**
|
||||
* FIXME: What's the best way to get the extension point registry upon deserialization?
|
||||
* We can expose a method to receive the extension point registry
|
||||
*/
|
||||
private static EndpointSerializer serializer;
|
||||
private EndpointSerializer serializer;
|
||||
private String xml;
|
||||
|
||||
/**
|
||||
|
@ -48,9 +45,6 @@ public class RuntimeEndpointImpl extends EndpointImpl implements Externalizable
|
|||
|
||||
public RuntimeEndpointImpl(ExtensionPointRegistry registry) {
|
||||
super(registry);
|
||||
if (registry != null) {
|
||||
serializer = new EndpointSerializerImpl(registry);
|
||||
}
|
||||
}
|
||||
|
||||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
|
||||
|
@ -61,7 +55,19 @@ public class RuntimeEndpointImpl extends EndpointImpl implements Externalizable
|
|||
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
out.writeUTF(getURI());
|
||||
out.writeUTF(serializer.write(this));
|
||||
out.writeUTF(getSerializer().write(this));
|
||||
}
|
||||
|
||||
private synchronized EndpointSerializer getSerializer() {
|
||||
if (serializer == null) {
|
||||
if (registry != null) {
|
||||
serializer =
|
||||
registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(EndpointSerializer.class);
|
||||
} else {
|
||||
throw new IllegalStateException("No extension registry is set");
|
||||
}
|
||||
}
|
||||
return serializer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -74,7 +80,7 @@ public class RuntimeEndpointImpl extends EndpointImpl implements Externalizable
|
|||
protected void resolve() {
|
||||
if (component == null && xml != null) {
|
||||
try {
|
||||
serializer.read(this, xml);
|
||||
getSerializer().read(this, xml);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
@ -82,4 +88,13 @@ public class RuntimeEndpointImpl extends EndpointImpl implements Externalizable
|
|||
super.resolve();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExtensionPointRegistry(ExtensionPointRegistry registry) {
|
||||
if (this.registry != registry) {
|
||||
super.setExtensionPointRegistry(registry);
|
||||
serializer = null;
|
||||
}
|
||||
// resolve();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tuscany.sca.core.assembly.impl;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
|
||||
import org.apache.tuscany.sca.assembly.impl.EndpointReferenceImpl;
|
||||
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
|
||||
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
|
||||
import org.apache.tuscany.sca.core.assembly.EndpointSerializer;
|
||||
|
||||
/**
|
||||
* Runtime model for Endpoint that supports java serialization
|
||||
*/
|
||||
public class RuntimeEndpointReferenceImpl extends EndpointReferenceImpl implements Externalizable {
|
||||
private EndpointSerializer serializer;
|
||||
private String xml;
|
||||
|
||||
/**
|
||||
* No-arg constructor for Java serilization
|
||||
*/
|
||||
public RuntimeEndpointReferenceImpl() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
public RuntimeEndpointReferenceImpl(ExtensionPointRegistry registry) {
|
||||
super(registry);
|
||||
}
|
||||
|
||||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
|
||||
this.uri = in.readUTF();
|
||||
this.xml = in.readUTF();
|
||||
// Defer the loading to resolve();
|
||||
}
|
||||
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
out.writeUTF(getURI());
|
||||
out.writeUTF(getSerializer().write(this));
|
||||
}
|
||||
|
||||
private synchronized EndpointSerializer getSerializer() {
|
||||
if (serializer == null) {
|
||||
if (registry != null) {
|
||||
serializer =
|
||||
registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(EndpointSerializer.class);
|
||||
} else {
|
||||
throw new IllegalStateException("No extension registry is set");
|
||||
}
|
||||
}
|
||||
return serializer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() {
|
||||
super.reset();
|
||||
this.xml = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resolve() {
|
||||
if (component == null && xml != null) {
|
||||
try {
|
||||
getSerializer().read(this, xml);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
super.resolve();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExtensionPointRegistry(ExtensionPointRegistry registry) {
|
||||
if (this.registry != registry) {
|
||||
super.setExtensionPointRegistry(registry);
|
||||
serializer = null;
|
||||
}
|
||||
// resolve();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
org.apache.tuscany.sca.core.assembly.impl.EndpointSerializerImpl
|
|
@ -16,6 +16,7 @@ Import-Package: org.apache.catalina.tribes,
|
|||
org.apache.catalina.tribes.group,
|
||||
org.apache.catalina.tribes.membership,
|
||||
org.apache.catalina.tribes.tipis,
|
||||
org.apache.juli.logging;resolution:=optional,
|
||||
org.apache.tuscany.sca.assembly;version="2.0.0",
|
||||
org.apache.tuscany.sca.core;version="2.0.0",
|
||||
org.apache.tuscany.sca.policy;version="2.0.0",
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.apache.catalina.tribes.group.GroupChannel;
|
|||
import org.apache.catalina.tribes.membership.McastService;
|
||||
import org.apache.catalina.tribes.tipis.AbstractReplicatedMap;
|
||||
import org.apache.catalina.tribes.tipis.ReplicatedMap;
|
||||
import org.apache.catalina.tribes.tipis.AbstractReplicatedMap.MapEntry;
|
||||
import org.apache.tuscany.sca.assembly.Endpoint;
|
||||
import org.apache.tuscany.sca.assembly.EndpointReference;
|
||||
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
|
||||
|
@ -57,6 +58,7 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry {
|
|||
private List<EndpointReference> endpointreferences = new CopyOnWriteArrayList<EndpointReference>();
|
||||
private List<EndpointListener> listeners = new CopyOnWriteArrayList<EndpointListener>();
|
||||
|
||||
private ExtensionPointRegistry registry;
|
||||
private ReplicatedMap map;
|
||||
|
||||
private static final Channel createChannel(String address, int port, String bindAddress) {
|
||||
|
@ -70,15 +72,34 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry {
|
|||
// REVIEW: In my case, there are multiple IP addresses
|
||||
// One for the WIFI and the other one for VPN. For some reason the VPN one doesn't support
|
||||
// Multicast
|
||||
/*
|
||||
try {
|
||||
Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
|
||||
while (nis.hasMoreElements()) {
|
||||
NetworkInterface ni = nis.nextElement();
|
||||
if (ni.isLoopback() || !ni.isUp() || !ni.supportsMulticast()) {
|
||||
continue;
|
||||
}
|
||||
Enumeration<InetAddress> ips = ni.getInetAddresses();
|
||||
while (ips.hasMoreElements()) {
|
||||
InetAddress addr = ips.nextElement();
|
||||
System.out.println(addr.getHostAddress());
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
*/
|
||||
if (bindAddress != null) {
|
||||
mcastService.setBind(bindAddress);
|
||||
}
|
||||
|
||||
mcastService.setBind("192.168.1.100");
|
||||
// mcastService.setBind("192.168.1.100");
|
||||
return channel;
|
||||
}
|
||||
|
||||
public ReplicatedEndpointRegistry(ExtensionPointRegistry registry, Map<String, String> attributes) {
|
||||
this.registry = registry;
|
||||
String portStr = attributes.get("port");
|
||||
if (portStr != null) {
|
||||
port = Integer.parseInt(portStr);
|
||||
|
@ -111,8 +132,18 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry {
|
|||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
Channel channel = map.getChannel();
|
||||
map.breakdown();
|
||||
try {
|
||||
channel.stop(Channel.DEFAULT);
|
||||
} catch (ChannelException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void addEndpoint(Endpoint endpoint) {
|
||||
map.put(getURI(endpoint), endpoint);
|
||||
map.put(endpoint.getURI(), endpoint);
|
||||
for (EndpointListener listener : listeners) {
|
||||
listener.endpointAdded(endpoint);
|
||||
}
|
||||
|
@ -183,6 +214,10 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry {
|
|||
Endpoint endpoint = (Endpoint)v;
|
||||
// TODO: implement more complete matching
|
||||
if (matches(targetEndpoint.getURI(), endpoint.getURI())) {
|
||||
MapEntry entry = map.getInternal(endpoint.getURI());
|
||||
if (!entry.isPrimary()) {
|
||||
endpoint.setExtensionPointRegistry(registry);
|
||||
}
|
||||
foundEndpoints.add(endpoint);
|
||||
logger.info("EndpointRegistry: Found endpoint with matching service - " + endpoint);
|
||||
}
|
||||
|
@ -212,18 +247,8 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry {
|
|||
return listeners;
|
||||
}
|
||||
|
||||
private String getURI(Endpoint ep) {
|
||||
String bindingName = ep.getBinding().getName();
|
||||
if (bindingName == null) {
|
||||
bindingName = ep.getService().getName();
|
||||
}
|
||||
String epURI =
|
||||
ep.getComponent().getURI() + "#service-binding(" + ep.getService().getName() + "/" + bindingName + ")";
|
||||
return epURI;
|
||||
}
|
||||
|
||||
public void removeEndpoint(Endpoint endpoint) {
|
||||
map.remove(getURI(endpoint));
|
||||
map.remove(endpoint.getURI());
|
||||
for (EndpointListener listener : listeners) {
|
||||
listener.endpointRemoved(endpoint);
|
||||
}
|
||||
|
@ -244,7 +269,7 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry {
|
|||
if (oldEndpoint == null) {
|
||||
throw new IllegalArgumentException("Endpoint is not found: " + uri);
|
||||
}
|
||||
map.put(getURI(endpoint), endpoint);
|
||||
map.put(endpoint.getURI(), endpoint);
|
||||
for (EndpointListener listener : listeners) {
|
||||
listener.endpointUpdated(oldEndpoint, endpoint);
|
||||
}
|
||||
|
@ -273,7 +298,7 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry {
|
|||
for (Object e : map.entrySetFull()) {
|
||||
Map.Entry en = (Map.Entry)e;
|
||||
AbstractReplicatedMap.MapEntry entry = (AbstractReplicatedMap.MapEntry)en.getValue();
|
||||
entry.isPrimary();
|
||||
System.out.println(entry);
|
||||
}
|
||||
map.breakdown();
|
||||
channel.stop(Channel.DEFAULT);
|
||||
|
|
Loading…
Reference in a new issue