forked from SilverThings/SilverWare
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SilverThings#4 getting ready for cluster invocations
- Loading branch information
Showing
8 changed files
with
111 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,10 +26,18 @@ | |
import org.jgroups.ReceiverAdapter; | ||
import org.jgroups.View; | ||
import org.silverware.microservices.Context; | ||
import org.silverware.microservices.MicroserviceMetaData; | ||
import org.silverware.microservices.providers.MicroserviceProvider; | ||
import org.silverware.microservices.silver.ClusterSilverService; | ||
import org.silverware.microservices.silver.cluster.ServiceHandle; | ||
import org.silverware.microservices.util.Utils; | ||
|
||
import java.util.Map; | ||
import java.util.Queue; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentLinkedQueue; | ||
|
||
/** | ||
* @author Martin Večeřa <[email protected]> | ||
*/ | ||
|
@@ -40,6 +48,8 @@ public class ClusterMicroserviceProvider implements MicroserviceProvider, Cluste | |
private Context context; | ||
private JChannel channel; | ||
private ChannelReceiver receiver; | ||
private Map<MicroserviceMetaData, Set<ServiceHandle>> outboundHandles = new ConcurrentHashMap<>(); | ||
private Queue<MicroserviceMetaData> toLookup = new ConcurrentLinkedQueue<>(); | ||
|
||
@Override | ||
public void initialize(final Context context) { | ||
|
@@ -82,6 +92,16 @@ public void run() { | |
} | ||
} | ||
|
||
@Override | ||
public Set<Object> lookupMicroservice(final MicroserviceMetaData metaData) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Set<Object> lookupLocalMicroservice(final MicroserviceMetaData metaData) { | ||
return null; | ||
} | ||
|
||
private static class ChannelReceiver extends ReceiverAdapter { | ||
@Override | ||
public void receive(final Message msg) { | ||
|
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
62 changes: 62 additions & 0 deletions
62
...n/java/org/silverware/microservices/providers/http/invoker/internal/HttpServiceProxy.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,62 @@ | ||
/* | ||
* -----------------------------------------------------------------------\ | ||
* SilverWare | ||
* | ||
* Copyright (C) 2010 - 2013 the original author or authors. | ||
* | ||
* Licensed 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.silverware.microservices.providers.http.invoker.internal; | ||
|
||
import org.silverware.microservices.Context; | ||
import org.silverware.microservices.silver.cluster.ServiceHandle; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import javassist.util.proxy.MethodHandler; | ||
import javassist.util.proxy.ProxyFactory; | ||
|
||
/** | ||
* @author Martin Večeřa <[email protected]> | ||
*/ | ||
public class HttpServiceProxy implements MethodHandler { | ||
|
||
private final Context context; | ||
private final ServiceHandle serviceHandle; | ||
|
||
private HttpServiceProxy(final Context context, final ServiceHandle serviceHandle) { | ||
this.context = context; | ||
this.serviceHandle = serviceHandle; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static <T> T getProxy(final Context context, final ServiceHandle serviceHandle) { | ||
try { | ||
ProxyFactory factory = new ProxyFactory(); | ||
if (serviceHandle.getQuery().getType().isInterface()) { | ||
factory.setInterfaces(new Class[] { serviceHandle.getQuery().getType() }); | ||
} else { | ||
factory.setSuperclass(serviceHandle.getQuery().getType()); | ||
} | ||
return (T) factory.create(new Class[0], new Object[0], new HttpServiceProxy(context, serviceHandle)); | ||
} catch (Exception e) { | ||
throw new IllegalStateException("Cannot create Http proxy for class " + serviceHandle.getQuery().getType().getName() + ": ", e); | ||
} | ||
} | ||
|
||
@Override | ||
public Object invoke(final Object o, final Method method, final Method method1, final Object[] objects) throws Throwable { | ||
return serviceHandle.invoke(context, method.getName(), objects); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
* | ||
* @author Martin Večeřa <[email protected]> | ||
*/ | ||
public interface ClusterSilverService extends SilverService { | ||
public interface ClusterSilverService extends ProvidingSilverService { | ||
|
||
/** | ||
* Property with the cluster group name. | ||
|
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