Author: isilval
Date: Tue Feb 20 13:09:47 2007
New Revision: 509756

URL: http://svn.apache.org/viewvc?view=rev&rev=509756
Log:
Update to wire changes

Modified:
    
incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/LocalNotificationComponent.java
    
incubator/tuscany/sandbox/isilval/notification/local/src/test/java/org/apache/tuscany/notification/local/LocalNotificationComponentTestCase.java

Modified: 
incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/LocalNotificationComponent.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/LocalNotificationComponent.java?view=diff&rev=509756&r1=509755&r2=509756
==============================================================================
--- 
incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/LocalNotificationComponent.java
 (original)
+++ 
incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/LocalNotificationComponent.java
 Tue Feb 20 13:09:47 2007
@@ -18,11 +18,11 @@
  */
 package org.apache.tuscany.notification.local;
 
+import java.lang.reflect.InvocationTargetException;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.tuscany.spi.ObjectCreationException;
 import org.apache.tuscany.spi.component.TargetInvokerCreationException;
@@ -30,15 +30,15 @@
 import org.apache.tuscany.spi.component.WorkContext;
 import org.apache.tuscany.spi.extension.AtomicComponentExtension;
 import org.apache.tuscany.spi.extension.ExecutionMonitor;
+import org.apache.tuscany.spi.extension.TargetInvokerExtension;
 import org.apache.tuscany.spi.model.Operation;
 import org.apache.tuscany.spi.services.work.WorkScheduler;
-import org.apache.tuscany.spi.wire.InboundInvocationChain;
-import org.apache.tuscany.spi.wire.InboundWire;
 import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
 import org.apache.tuscany.spi.wire.Message;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
-import org.apache.tuscany.spi.wire.OutboundWire;
 import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
 import org.apache.tuscany.spi.wire.WireService;
 
 /**
@@ -49,7 +49,7 @@
 public class LocalNotificationComponent extends AtomicComponentExtension {
 
     private static final Message RESPONSE = new ImmutableMessage();
-    private LocalNotificationInterceptor notificationInterceptor = null;
+    private List<Wire> wires;
 
     public LocalNotificationComponent(URI name,
                                        WireService wireService,
@@ -71,45 +71,45 @@
         return this;
     }
     
-    public TargetInvoker createTargetInvoker(String targetName, Operation 
operation, InboundWire callbackWire)
+    public TargetInvoker createTargetInvoker(String targetName, Operation 
operation)
         throws TargetInvokerCreationException {
         
-        return null;
+        return new LocalNotificationTargetInvoker(operation, workContext, 
monitor);
     }
 
-    protected void onServiceWire(InboundWire serviceWire) {
-        if (notificationInterceptor != null) {
-            throw new MultipleServiceWiresException("Only one service wire 
allowed");
-        }
-        // Assuming there is only one service wire
-        notificationInterceptor = new LocalNotificationInterceptor();
-        InboundInvocationChain serviceChain = 
serviceWire.getInboundInvocationChains().values().iterator().next();
-        serviceChain.addInterceptor(0, notificationInterceptor);
+    public List<Wire> getWires(String name) {
+        return null;
     }
 
-    protected void onReferenceWires(List<OutboundWire> wires) {
-        for (OutboundWire referenceWire : wires) {
-            Map<?,OutboundInvocationChain> referenceChains = 
referenceWire.getOutboundInvocationChains();
-            OutboundInvocationChain referenceChain = 
referenceChains.values().iterator().next();
-            
notificationInterceptor.addSubscriberInterceptor(referenceChain.getTailInterceptor().getNext());
-            System.out.println("*** added sub interceptor");
-        }
-    }
+    public void attachWire(Wire wire) {
 
-    public void prepare() /* throws PrepareException */ {
-        for (List<OutboundWire> list : referenceWires.values()) {
-            OutboundWire referenceWire = list.get(0);
-            Map<?,OutboundInvocationChain> referenceChains = 
referenceWire.getOutboundInvocationChains();
-            OutboundInvocationChain referenceChain = 
referenceChains.values().iterator().next();
-            
notificationInterceptor.addSubscriberInterceptor(referenceChain.getTailInterceptor().getNext());
-        }
+        throw new AssertionError();
     }
     
-    class LocalNotificationInterceptor implements Interceptor {
+    public void attachWires(List<Wire> attachWires) {
+        
+        wires = attachWires;
+    }
+    
+    public void attachCallbackWire(Wire wire) {
+        
+        throw new AssertionError();
+    }
+    
+    class LocalNotificationTargetInvoker extends TargetInvokerExtension {
         
         private List<Interceptor> subscriberInterceptors;
         
-        public Message invoke(Message msg) {
+        public LocalNotificationTargetInvoker(Operation operation, WorkContext 
wc, ExecutionMonitor mon) {
+            super(wc, mon);
+            subscriberInterceptors = new ArrayList<Interceptor>();
+            for (Wire wire : wires) {
+                InvocationChain chain = 
wire.getInvocationChains().get(operation);
+                subscriberInterceptors.add(chain.getHeadInterceptor());
+            }
+        }
+
+        public Message invoke(Message msg) throws InvocationRuntimeException {
             // REVIEW Should this be done in separate thread(s)?
             // REVIEW Should separate copies of message be used?
             for (Interceptor subscriberInterceptor : subscriberInterceptors) {
@@ -119,26 +119,12 @@
             return RESPONSE;
         }
         
-        public void addSubscriberInterceptor(Interceptor subInt) {
-            if (subscriberInterceptors == null) {
-                subscriberInterceptors = new ArrayList<Interceptor>();
-            }
-            subscriberInterceptors.add(subInt);
-        }
-
-        public void setNext(Interceptor next) {
+        public Object invokeTarget(final Object payload, final short sequence) 
throws InvocationTargetException {
             
-        }
-
-        public Interceptor getNext() {
-            return null;
-        }
-
-        public boolean isOptimizable() {
-            return false;
+            throw new AssertionError();
         }
     }
-
+    
     private static class ImmutableMessage implements Message {
 
         public Object getBody() {
@@ -163,27 +149,23 @@
             return null;
         }
 
-        public Object getFromAddress() {
+        public URI getFromAddress() {
             return null;
         }
 
-        public void setFromAddress(Object fromAddress) {
+        public void setFromAddress(URI fromAddress) {
             throw new UnsupportedOperationException();
         }
 
-        public URI popFromAddress() {
-            return null;
-        }
-
-        public void pushFromAddress(URI fromAddress) {
+        public void pushCallbackUri(URI fromAddress) {
             throw new UnsupportedOperationException();
         }
 
-        public LinkedList<URI> getCallbackRoutingChain() {
+        public LinkedList<URI> getCallbackUris() {
             return null;
         }
 
-        public void setCallbackRoutingChain(LinkedList<URI> fromAddresses) {
+        public void setCallbackUris(LinkedList<URI> uris) {
             throw new UnsupportedOperationException();
         }
 
@@ -218,6 +200,5 @@
         public void setConversationSequence(short sequence) {
 
         }
-
     }
 }

Modified: 
incubator/tuscany/sandbox/isilval/notification/local/src/test/java/org/apache/tuscany/notification/local/LocalNotificationComponentTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/isilval/notification/local/src/test/java/org/apache/tuscany/notification/local/LocalNotificationComponentTestCase.java?view=diff&rev=509756&r1=509755&r2=509756
==============================================================================
--- 
incubator/tuscany/sandbox/isilval/notification/local/src/test/java/org/apache/tuscany/notification/local/LocalNotificationComponentTestCase.java
 (original)
+++ 
incubator/tuscany/sandbox/isilval/notification/local/src/test/java/org/apache/tuscany/notification/local/LocalNotificationComponentTestCase.java
 Tue Feb 20 13:09:47 2007
@@ -25,13 +25,11 @@
 import java.util.Map;
 
 import org.apache.tuscany.spi.model.Operation;
-import org.apache.tuscany.spi.wire.InboundInvocationChain;
-import org.apache.tuscany.spi.wire.InboundWire;
 import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
 import org.apache.tuscany.spi.wire.Message;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
-import org.apache.tuscany.spi.wire.OutboundWire;
 import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
 import org.easymock.EasyMock;
 
 import junit.framework.Assert;
@@ -50,141 +48,60 @@
         
         Operation<Type> operation = new Operation<Type>("test", null, null, 
null);
         
-        InboundInvocationChain pubChain = new MockInboundInvocationChain();
-        Map<Operation<?>, InboundInvocationChain> pubChains = new 
HashMap<Operation<?>, InboundInvocationChain>();
-        pubChains.put(operation, pubChain);
-        InboundWire pubWire = EasyMock.createNiceMock(InboundWire.class);
-        
EasyMock.expect(pubWire.getSourceUri()).andReturn(URI.create("pubWire"));
-        
EasyMock.expect(pubWire.getInboundInvocationChains()).andReturn(pubChains);
-        EasyMock.replay(pubWire);
-        
-        Interceptor sub1TailInterceptor = 
EasyMock.createNiceMock(Interceptor.class);
-        EasyMock.expect(sub1TailInterceptor.getNext()).andReturn(new 
MockInterceptor("Sub1"));
-        EasyMock.replay(sub1TailInterceptor);
-        OutboundInvocationChain sub1Chain = 
EasyMock.createNiceMock(OutboundInvocationChain.class);
-        
EasyMock.expect(sub1Chain.getTailInterceptor()).andReturn(sub1TailInterceptor);
+        InvocationChain sub1Chain = 
EasyMock.createNiceMock(InvocationChain.class);
+        EasyMock.expect(sub1Chain.getHeadInterceptor()).andReturn(new 
MockInterceptor());
         EasyMock.replay(sub1Chain);
-        Map<Operation<?>, OutboundInvocationChain> sub1Chains = new 
HashMap<Operation<?>, OutboundInvocationChain>();
+        Map<Operation<?>, InvocationChain> sub1Chains = new 
HashMap<Operation<?>, InvocationChain>();
         sub1Chains.put(operation, sub1Chain);
-        OutboundWire sub1Wire = EasyMock.createNiceMock(OutboundWire.class);
+        Wire sub1Wire = EasyMock.createNiceMock(Wire.class);
         URI sub1Name = URI.create("sub1Wire#sub1fragment");
         EasyMock.expect(sub1Wire.getSourceUri()).andReturn(sub1Name);
-        
EasyMock.expect(sub1Wire.getOutboundInvocationChains()).andReturn(sub1Chains);
+        EasyMock.expect(sub1Wire.getInvocationChains()).andReturn(sub1Chains);
         EasyMock.replay(sub1Wire);
         
-        Interceptor sub2TailInterceptor = 
EasyMock.createNiceMock(Interceptor.class);
-        EasyMock.expect(sub2TailInterceptor.getNext()).andReturn(new 
MockInterceptor("Sub2"));
-        EasyMock.replay(sub2TailInterceptor);
-        OutboundInvocationChain sub2Chain = 
EasyMock.createNiceMock(OutboundInvocationChain.class);
-        
EasyMock.expect(sub2Chain.getTailInterceptor()).andReturn(sub2TailInterceptor);
+        InvocationChain sub2Chain = 
EasyMock.createNiceMock(InvocationChain.class);
+        EasyMock.expect(sub2Chain.getHeadInterceptor()).andReturn(new 
MockInterceptor());
         EasyMock.replay(sub2Chain);
-        Map<Operation<?>, OutboundInvocationChain> sub2Chains = new 
HashMap<Operation<?>, OutboundInvocationChain>();
+        Map<Operation<?>, InvocationChain> sub2Chains = new 
HashMap<Operation<?>, InvocationChain>();
         sub2Chains.put(operation, sub2Chain);
-        OutboundWire sub2Wire = EasyMock.createNiceMock(OutboundWire.class);
+        Wire sub2Wire = EasyMock.createNiceMock(Wire.class);
         URI sub2Name = URI.create("sub2Wire#sub2fragment");
         EasyMock.expect(sub2Wire.getSourceUri()).andReturn(sub2Name);
-        
EasyMock.expect(sub2Wire.getOutboundInvocationChains()).andReturn(sub2Chains);
+        EasyMock.expect(sub2Wire.getInvocationChains()).andReturn(sub2Chains);
         EasyMock.replay(sub2Wire);
         
-        nc.addInboundWire(pubWire);
-        ArrayList<OutboundWire> outboundWires = new ArrayList<OutboundWire>();
-        outboundWires.add(sub1Wire);
-        outboundWires.add(sub2Wire);
-        nc.addOutboundWires(outboundWires);
+        ArrayList<Wire> wires = new ArrayList<Wire>();
+        wires.add(sub1Wire);
+        wires.add(sub2Wire);
+        nc.attachWires(wires);
         
-        MockInterceptor pubInterceptor = new MockInterceptor("Pub");
-        pubInterceptor.setNext(pubChain.getHeadInterceptor());
+        // Notice that if we try to create the invoker before attaching wires, 
it won't work
+        TargetInvoker localNotificationInvoker = nc.createTargetInvoker("", 
operation);
         
         Message msg = EasyMock.createNiceMock(Message.class);
         EasyMock.expect(msg.getBody()).andReturn("msg").times(2);
         EasyMock.replay(msg);
-        pubInterceptor.invoke(msg);
+        localNotificationInvoker.invoke(msg);
         EasyMock.verify(msg);
     }
     
-    class MockInboundInvocationChain implements InboundInvocationChain {
-        
-        private Interceptor head = null;
-        
-        public Operation getOperation() {
-            Assert.fail();
-            return null;
-        }
-
-        public void setTargetInvoker(TargetInvoker invoker) {
-            Assert.fail();
-        }
-
-        public TargetInvoker getTargetInvoker() {
-            Assert.fail();
-            return null;
-        }
-
-        public void addInterceptor(Interceptor interceptor) {
-            Assert.fail();
-        }
-
-        public void addInterceptor(int index, Interceptor interceptor) {
-            Assert.assertEquals(index, 0);
-            Assert.assertNotNull(interceptor);
-            head = interceptor;
-        }
-
-        public Interceptor getHeadInterceptor() {
-            Assert.assertNotNull(head);
-            return head;
-        }
-
-        public Interceptor getTailInterceptor() {
-            Assert.fail();
-            return null;
-        }
-
-        public void setTargetInterceptor(Interceptor interceptor) {
-            Assert.fail();
-        }
-
-        public Interceptor getTargetInterceptor() {
-            Assert.fail();
-            return null;
-        }
-
-        public void prepare() {
-            Assert.fail();
-        }
-    }
-    
     class MockInterceptor implements Interceptor {
         
-        private String name;
-        private Interceptor next;
-        
-        public MockInterceptor(String name) {
-            this.name = name;
-        }
-        
         public Message invoke(Message msg) {
-            if (name.equals("Pub")) {
-                return next.invoke(msg);
-            }
-            else {
-                Assert.assertEquals(msg.getBody(), "msg");
-                return msg;
-            }
+            Assert.assertEquals(msg.getBody(), "msg");
+            return msg;
         }
         
         public void setNext(Interceptor next) {
-            this.next = next;
+            throw new AssertionError();
         }
 
         public Interceptor getNext() {
-            Assert.fail();
-            return null;
+            throw new AssertionError();
         }
 
         public boolean isOptimizable() {
-            Assert.fail();
-            return false;
+            throw new AssertionError();
         }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to