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.
Re-implementation of rest-client-microservice-provider using Resteasy…
… clien API proxy framework. Removed old implementation and cdi rest gateway implementation.
- Loading branch information
1 parent
e5cbdaf
commit 18946af
Showing
21 changed files
with
511 additions
and
910 deletions.
There are no files selected for viewing
39 changes: 0 additions & 39 deletions
39
cdi-microservice-provider/src/main/java/io/silverware/microservices/annotations/Gateway.java
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
...icroservice-provider/src/main/java/io/silverware/microservices/annotations/ParamName.java
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -30,7 +30,6 @@ | |
import io.silverware.microservices.providers.cdi.internal.MicroserviceProxyBean; | ||
import io.silverware.microservices.providers.cdi.internal.MicroservicesCDIExtension; | ||
import io.silverware.microservices.providers.cdi.internal.MicroservicesInitEvent; | ||
import io.silverware.microservices.providers.cdi.internal.RestInterface; | ||
import io.silverware.microservices.silver.CdiSilverService; | ||
import io.silverware.microservices.util.Utils; | ||
|
||
|
@@ -39,6 +38,13 @@ | |
import org.jboss.weld.environment.se.Weld; | ||
import org.jboss.weld.environment.se.WeldContainer; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import javax.annotation.Priority; | ||
import javax.enterprise.context.Dependent; | ||
import javax.enterprise.context.spi.CreationalContext; | ||
|
@@ -50,13 +56,6 @@ | |
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Martin Večeřa</a> | ||
*/ | ||
|
@@ -81,12 +80,12 @@ public void initialize(final Context context) { | |
|
||
@Override | ||
public Context getContext() { | ||
return context; | ||
return this.context; | ||
} | ||
|
||
@Override | ||
public boolean isDeployed() { | ||
return deployed; | ||
return this.deployed; | ||
} | ||
|
||
@Override | ||
|
@@ -95,49 +94,44 @@ public void run() { | |
log.info("Hello from CDI microservice provider!"); | ||
|
||
final Weld weld = new Weld(); | ||
final RestInterface rest = new RestInterface(context); | ||
final MicroservicesCDIExtension microservicesCDIExtension = new MicroservicesCDIExtension(context, rest); | ||
final MicroservicesCDIExtension microservicesCDIExtension = new MicroservicesCDIExtension(this.context); | ||
System.setProperty("org.jboss.weld.se.archive.isolation", "false"); | ||
weld.addExtension(microservicesCDIExtension); | ||
|
||
final WeldContainer container = weld.initialize(); | ||
context.getProperties().put(BEAN_MANAGER, container.getBeanManager()); | ||
context.getProperties().put(CDI_CONTAINER, container); | ||
context.getProperties().put(Storage.STORAGE, new HashMap<String, Object>()); | ||
this.context.getProperties().put(BEAN_MANAGER, container.getBeanManager()); | ||
this.context.getProperties().put(CDI_CONTAINER, container); | ||
this.context.getProperties().put(Storage.STORAGE, new HashMap<String, Object>()); | ||
|
||
log.info("Discovered the following microservice implementations:"); | ||
context.getMicroservices().forEach(metaData -> log.info((" - " + metaData.toString()))); | ||
this.context.getMicroservices().forEach(metaData -> log.info((" - " + metaData.toString()))); | ||
|
||
log.info("Total count of discovered microservice injection points: " + microservicesCDIExtension.getInjectionPointsCount()); | ||
this.deployed = true; | ||
|
||
log.info("Deploying REST gateway services."); | ||
rest.deploy(); | ||
|
||
deployed = true; | ||
|
||
container.event().select(MicroservicesInitEvent.class).fire(new MicroservicesInitEvent(context, container.getBeanManager(), container)); | ||
container.event().select(MicroservicesStartedEvent.class).fire(new MicroservicesStartedEvent(context, container.getBeanManager(), container)); | ||
container.event().select(MicroservicesInitEvent.class).fire(new MicroservicesInitEvent(this.context, container.getBeanManager(), container)); | ||
container.event().select(MicroservicesStartedEvent.class).fire(new MicroservicesStartedEvent(this.context, container.getBeanManager(), container)); | ||
|
||
try { | ||
while (!Thread.currentThread().isInterrupted()) { | ||
Thread.sleep(1000); | ||
} | ||
} catch (InterruptedException ie) { | ||
} catch (final InterruptedException ie) { | ||
Utils.shutdownLog(log, ie); | ||
} finally { | ||
deployed = false; | ||
rest.undeploy(); | ||
this.deployed = false; | ||
try { | ||
weld.shutdown(); | ||
} catch (IllegalStateException e) { | ||
} catch (final IllegalStateException e) { | ||
// nothing, this is just fine, weld was already terminated | ||
} | ||
} | ||
} catch (Exception e) { | ||
} catch (final Exception e) { | ||
log.error("CDI microservice provider failed: ", e); | ||
} | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("checkstyle:JavadocMethod") | ||
public Set<Object> lookupMicroservice(final MicroserviceMetaData microserviceMetaData) { | ||
final String name = microserviceMetaData.getName(); | ||
|
@@ -158,9 +152,9 @@ public Set<Object> lookupMicroservice(final MicroserviceMetaData microserviceMet | |
In all cases, there must be precisely one result or an error is thrown. | ||
*/ | ||
|
||
final BeanManager beanManager = ((BeanManager) context.getProperties().get(BEAN_MANAGER)); | ||
Set<Bean<?>> beans = beanManager.getBeans(type, qualifiers.toArray(new Annotation[qualifiers.size()])); | ||
for (Bean<?> bean : beans) { | ||
final BeanManager beanManager = ((BeanManager) this.context.getProperties().get(BEAN_MANAGER)); | ||
final Set<Bean<?>> beans = beanManager.getBeans(type, qualifiers.toArray(new Annotation[qualifiers.size()])); | ||
for (final Bean<?> bean : beans) { | ||
if (bean.getBeanClass().isAnnotationPresent(Microservice.class) && !(bean instanceof MicroserviceProxyBean)) { | ||
final Bean<?> theBean = beanManager.resolve(Collections.singleton(bean)); | ||
final Microservice microserviceAnnotation = theBean.getBeanClass().getAnnotation(Microservice.class); | ||
|
@@ -223,17 +217,17 @@ static Object getMicroserviceProxy(final Context context, final Class clazz, fin | |
} | ||
|
||
public <T> T lookupBean(final Class<T> type) { | ||
return ((WeldContainer) context.getProperties().get(CDI_CONTAINER)).instance().select(type).get(); | ||
return ((WeldContainer) this.context.getProperties().get(CDI_CONTAINER)).instance().select(type).get(); | ||
} | ||
|
||
@Override | ||
public <T> T findByType(Class<T> type) { | ||
BeanManager beanManager = (BeanManager) context.getProperties().get(BEAN_MANAGER); | ||
Set<T> beans = new HashSet<T>(); | ||
Set<Bean<?>> definitions = beanManager.getBeans(type); | ||
Bean<?> bean = beanManager.resolve(definitions); | ||
CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean); | ||
Object result = beanManager.getReference(bean, type, creationalContext); | ||
public <T> T findByType(final Class<T> type) { | ||
final BeanManager beanManager = (BeanManager) this.context.getProperties().get(BEAN_MANAGER); | ||
final Set<T> beans = new HashSet<T>(); | ||
final Set<Bean<?>> definitions = beanManager.getBeans(type); | ||
final Bean<?> bean = beanManager.resolve(definitions); | ||
final CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean); | ||
final Object result = beanManager.getReference(bean, type, creationalContext); | ||
|
||
return result == null ? null : type.cast(result); | ||
} | ||
|
@@ -248,7 +242,7 @@ public MicroserviceReferenceLiteral(final String name) { | |
|
||
@Override | ||
public String value() { | ||
return name; | ||
return this.name; | ||
} | ||
} | ||
|
||
|
@@ -273,10 +267,10 @@ public static class SilverWareConfiguration implements Configuration { | |
|
||
@Override | ||
public Object getProperty(final String propertyName) { | ||
return context.getProperties().get(propertyName); | ||
return this.context.getProperties().get(propertyName); | ||
} | ||
|
||
public void eventObserver(@Observes MicroservicesInitEvent event) { | ||
public void eventObserver(@Observes final MicroservicesInitEvent event) { | ||
this.context = event.getContext(); | ||
} | ||
} | ||
|
@@ -288,7 +282,7 @@ public static class SilverWareStorage implements Storage { | |
private Context context; | ||
|
||
private Map<String, Object> getStorage() { | ||
return (Map<String, Object>) context.getProperties().get(STORAGE); | ||
return (Map<String, Object>) this.context.getProperties().get(STORAGE); | ||
} | ||
|
||
@Override | ||
|
@@ -306,7 +300,7 @@ public boolean drop(final String key) { | |
return getStorage().remove(key) != null; | ||
} | ||
|
||
public void eventObserver(@Observes MicroservicesInitEvent event) { | ||
public void eventObserver(@Observes final MicroservicesInitEvent event) { | ||
this.context = event.getContext(); | ||
} | ||
} | ||
|
@@ -319,10 +313,10 @@ public static class SilverWareCurrentContext implements CurrentContext { | |
|
||
@Override | ||
public Context getContext() { | ||
return context; | ||
return this.context; | ||
} | ||
|
||
public void eventObserver(@Observes MicroservicesInitEvent event) { | ||
public void eventObserver(@Observes final MicroservicesInitEvent event) { | ||
this.context = event.getContext(); | ||
} | ||
} | ||
|
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
Oops, something went wrong.