-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48e3647
commit 0c1b6fb
Showing
10 changed files
with
272 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.serious.channel; | ||
/* | ||
* @COPYRIGHT (C) 2016 Andreas Ernst | ||
* | ||
* All rights reserved | ||
*/ | ||
|
||
import com.serious.service.BaseDescriptor; | ||
import com.serious.service.ChannelManager; | ||
import com.serious.service.Service; | ||
import com.serious.service.channel.AbstractChannel; | ||
import org.aopalliance.intercept.MethodInvocation; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* @author Andreas Ernst | ||
*/ | ||
public class LocalChannel extends AbstractChannel { | ||
// constructor | ||
|
||
protected LocalChannel(ChannelManager channelManager) { | ||
super(channelManager); | ||
} | ||
|
||
// implement | ||
|
||
@Override | ||
public Object invoke(MethodInvocation invocation) throws Throwable { | ||
Object implementation = BaseDescriptor.forService((Class<Service>)invocation.getMethod().getDeclaringClass()).local; | ||
|
||
Method method = implementation.getClass().getMethod(invocation.getMethod().getName(), invocation.getMethod().getParameterTypes()); | ||
|
||
return method.invoke(implementation, invocation.getArguments()); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
core/src/test/java/com/serious/registry/LocalComponentRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.serious.registry; | ||
/* | ||
* @COPYRIGHT (C) 2016 Andreas Ernst | ||
* | ||
* All rights reserved | ||
*/ | ||
|
||
import com.serious.service.Component; | ||
import com.serious.service.ComponentDescriptor; | ||
import com.serious.service.ComponentRegistry; | ||
import com.serious.service.ServiceAddress; | ||
import org.springframework.cloud.client.ServiceInstance; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* @author Andreas Ernst | ||
*/ | ||
public class LocalComponentRegistry implements ComponentRegistry { | ||
// instance data | ||
|
||
Map<String, List<ServiceAddress>> services = new HashMap<>(); | ||
|
||
// implement ComponentRegistry | ||
|
||
@Override | ||
public void startup(ComponentDescriptor<Component> descriptor) { | ||
List<ServiceAddress> addresses = services.computeIfAbsent(descriptor.getName(), k -> | ||
new ArrayList<>() | ||
); | ||
|
||
addresses.addAll(descriptor.getExternalAddresses()); | ||
} | ||
|
||
@Override | ||
public void shutdown(ComponentDescriptor<Component> descriptor) { | ||
// noop | ||
} | ||
|
||
@Override | ||
public List<String> getServices() { | ||
return services.keySet().stream().toList(); | ||
} | ||
|
||
@Override | ||
public List<ServiceInstance> getInstances(String service) { | ||
return services.get(service).stream() | ||
.map(address -> address.getServiceInstance()) | ||
.collect(Collectors.toList()); | ||
} | ||
} | ||
|
Oops, something went wrong.