diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-18 00:29:15 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-18 00:29:15 +0000 |
commit | 50a856b26b629cbbfb0b18c9f8f8c8418209d19c (patch) | |
tree | a4e45bf017e4efd292dcfaa186a7b64425164066 /java/sca/modules/node-impl-osgi/src/test/java/calculator/dosgi/CalculatorServiceImpl.java | |
parent | efec32910420ff0a3316914668ff44d069d4a744 (diff) |
Add filter to select local or remote services
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@755452 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | java/sca/modules/node-impl-osgi/src/test/java/calculator/dosgi/CalculatorServiceImpl.java | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/java/sca/modules/node-impl-osgi/src/test/java/calculator/dosgi/CalculatorServiceImpl.java b/java/sca/modules/node-impl-osgi/src/test/java/calculator/dosgi/CalculatorServiceImpl.java index 6dc2e4c621..1634a1f2a4 100644 --- a/java/sca/modules/node-impl-osgi/src/test/java/calculator/dosgi/CalculatorServiceImpl.java +++ b/java/sca/modules/node-impl-osgi/src/test/java/calculator/dosgi/CalculatorServiceImpl.java @@ -34,12 +34,8 @@ import calculator.dosgi.operations.SubtractService; * An implementation of the Calculator service. */ public class CalculatorServiceImpl implements CalculatorService { - // private AddService addService; - // private SubtractService subtractService; - // private MultiplyService multiplyService; - // private DivideService divideService; - - private ServiceTracker tracker; + private ServiceTracker remoteServices; + private ServiceTracker localServices; public CalculatorServiceImpl() { super(); @@ -47,41 +43,34 @@ public class CalculatorServiceImpl implements CalculatorService { public CalculatorServiceImpl(BundleContext context) { super(); - Filter filter = null; + Filter remoteFilter = null, localFilter = null; try { - filter = context.createFilter("(&(" + OBJECTCLASS + "=calculator.dosgi.operations.*) (sca.reference=*))"); + remoteFilter = + context.createFilter("(&(" + OBJECTCLASS + "=calculator.dosgi.operations.*) (sca.reference=*))"); + localFilter = + context.createFilter("(&(" + OBJECTCLASS + "=calculator.dosgi.operations.*) (!(sca.reference=*)))"); } catch (InvalidSyntaxException e) { e.printStackTrace(); } - this.tracker = new ServiceTracker(context, filter, null); - tracker.open(); - } - - /* - * The following setters can be used for DS injection - */ - /* - public void setAddService(AddService addService) { - this.addService = addService; + this.remoteServices = new ServiceTracker(context, remoteFilter, null); + remoteServices.open(); + this.localServices = new ServiceTracker(context, localFilter, null); + localServices.open(); } - public void setSubtractService(SubtractService subtractService) { - this.subtractService = subtractService; - } - - public void setDivideService(DivideService divideService) { - this.divideService = divideService; - } - - public void setMultiplyService(MultiplyService multiplyService) { - this.multiplyService = multiplyService; - } - */ - private <T> T getService(Class<T> cls) { - for (Object s : tracker.getServices()) { + Object[] remoteObjects = remoteServices.getServices(); + if (remoteObjects != null) { + for (Object s : remoteObjects) { + if (cls.isInstance(s)) { + System.out.println("Remote service: " + s); + return cls.cast(s); + } + } + } + for (Object s : localServices.getServices()) { if (cls.isInstance(s)) { - System.out.println(s); + System.out.println("Local service: " + s); return cls.cast(s); } } |