You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by fi...@apache.org on 2011/07/21 17:56:20 UTC

svn commit: r1149242 - in /incubator/etch/branches/singlestack: binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/ binding-java/runtime/src/main/java/org/apache/etch/bindings/java/support/ util/src/main/java/org/apache/etc...

Author: fitzner
Date: Thu Jul 21 15:56:16 2011
New Revision: 1149242

URL: http://svn.apache.org/viewvc?rev=1149242&view=rev
Log:
ETCH-157 binding-java: add @Signal support

Similar to the csharp @Signal binding support.

Patch is from Aleksandar Kanchev <ka...@itestra.com>

Modified:
    incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/base.vm
    incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/impl.vm
    incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/intf.vm
    incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/remote.vm
    incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/stub.vm
    incubator/etch/branches/singlestack/binding-java/runtime/src/main/java/org/apache/etch/bindings/java/support/RemoteBase.java
    incubator/etch/branches/singlestack/util/src/main/java/org/apache/etch/util/core/io/InetWho.java

Modified: incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/base.vm
URL: http://svn.apache.org/viewvc/incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/base.vm?rev=1149242&r1=1149241&r2=1149242&view=diff
==============================================================================
--- incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/base.vm (original)
+++ incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/base.vm Thu Jul 21 15:56:16 2011
@@ -27,10 +27,19 @@
 #else
 #set($peer = "server")
 #end
+#set($whoType = "Who")
+#set($whoName = "sender")
+#set($hasSignals = false)
+#if ($intf.signals( false ).hasNext())
+#set($hasSignals = true)
+#end
 
 package $intf.parent().name();
 
 import org.apache.etch.bindings.java.support.ObjSession;
+#if ($hasSignals && $helper.isServer($mc))
+import org.apache.etch.util.core.Who;
+#end
 
 #foreach( $n in $intf.iterator() )
 #if ($n.isExtern())
@@ -49,6 +58,18 @@ import $n.getImport( $helper );
  */
 public class $clname implements $intfname, ObjSession
 {
+#if ($hasSignals && $helper.isServer($mc))
+	protected final Remote$intf.name()Client client;
+
+	/**
+	 * Constructs the $clname.
+	 */
+	public $clname(Remote$intf.name()Client client)
+	{
+		this.client = client;
+	}
+
+#end
 	public Object _sessionQuery( Object query ) throws Exception
 	{
 		throw new UnsupportedOperationException( "unknown query: "+query );
@@ -77,17 +98,32 @@ public class $clname implements $intfnam
 		$sep$helper.getTypeName( $param.type() ) $param.name()
 #set( $sep = ", " )
 #end
+#if ($mthd.hasSignal() && $mthd.isMsgDirServer())
+		$sep$whoType $whoName
+#end
 	)
-#if($mthd.hasThrown())
+#if($mthd.hasThrown() || ($mthd.hasSignal() && $mthd.isMsgDirServer()))
 	throws
 #set( $sep = "" )
 #foreach($t in $mthd.thrown().iterator())
 		$sep$t.getNamed().fqname()
 #set( $sep = ", " )
 #end
+#if ($mthd.hasSignal() && $mthd.isMsgDirServer())
+		Exception
+#end
 #end
 	{
+#if ($mthd.hasSignal() && $mthd.isMsgDirServer())
+#set( $subscription = "Add" )
+#if ($mthd.isSignalUnsubscribeMessage())
+#set( $subscription = "Remove" )
+#end
+		if (!client._$subscription$mthd.getMessageSignal().getSignalName()Subscriber( $whoName ))
+			throw new Exception( "Unable to $subscription subscriber" );
+#else
 		throw new UnsupportedOperationException( "$mthd.name()" );
+#end
 	}
 #end
 #end
@@ -124,6 +160,9 @@ public class $clname implements $intfnam
 		$sep$helper.getTypeName( $p.type() ) $p.name()
 #set( $sep = ", " )
 #end
+#if ($mthd.hasSignal() && $mthd.isMsgDirServer())
+		$sep$whoType $whoName
+#end
 	)
 #if($n.hasThrown())
 	throws
@@ -134,7 +173,15 @@ public class $clname implements $intfnam
 #end
 #end
 	{
+#if ($mthd.hasSignal() && $mthd.isMsgDirServer())
+#set( $subscription = "Add" )
+#if ($mthd.isSignalUnsubscribeMessage())
+#set( $subscription = "Remove" )
+#end
+		client._$subscription$mthd.getMessageSignal().getSignalName()Subscriber( $whoName );
+#else
 		throw new UnsupportedOperationException( "$n.name()" );
+#end
 	}
 #end
 #end

Modified: incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/impl.vm
URL: http://svn.apache.org/viewvc/incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/impl.vm?rev=1149242&r1=1149241&r2=1149242&view=diff
==============================================================================
--- incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/impl.vm (original)
+++ incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/impl.vm Thu Jul 21 15:56:16 2011
@@ -31,6 +31,10 @@
 #set($peer = "server")
 #set($peerclass = "Remote${i}Server")
 #end
+#set($hasSignals = false)
+#if ($intf.signals( false ).hasNext())
+#set($hasSignals = true)
+#end
 
 package $intf.parent().name();
 
@@ -48,8 +52,13 @@ public class $clname extends $baseclname
 	 */
 	public $clname( $peerclass $peer )
 	{
+#if ($hasSignals && $helper.isServer($mc))
+		super( $peer );
+#else
 		this.$peer = $peer;
+#end
 	}
+#if (!$hasSignals || !$helper.isServer($mc))
 	
 	/**
 	 * A connection to the $peer session. Use this to send a
@@ -57,7 +66,8 @@ public class $clname extends $baseclname
 	 */
 	@SuppressWarnings( "unused" )
 	private final $peerclass $peer;
-
+#end
+	
 	// TODO insert methods here to provide implementations of $intfname
 	// messages from the $peer.
 }
\ No newline at end of file

Modified: incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/intf.vm
URL: http://svn.apache.org/viewvc/incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/intf.vm?rev=1149242&r1=1149241&r2=1149242&view=diff
==============================================================================
--- incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/intf.vm (original)
+++ incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/intf.vm Thu Jul 21 15:56:16 2011
@@ -62,6 +62,7 @@ public interface $intf.name()$suffix
 #if ($n.isMessage())
 #if ($n.isMsgDir($mc))
 #if (!$n.isHidden())
+#if (!$n.hasSignal() || !$n.isMsgDirServer())
 	/**
 #foreach( $s in $n.descr() )
 	 * $s
@@ -118,6 +119,7 @@ public interface $intf.name()$suffix
 	;
 #end
 #end
+#end
 #elseif ($n.isConstant())
 #if (!$hasBaseClass)
 #if ($n.hasDescr())
@@ -283,7 +285,7 @@ public interface $intf.name()$suffix
 	}
 
 #end
-#elseif ($n.isBuiltin())
+#elseif ($n.isBuiltin() || $n.isSignal())
 ## nothing to do.
 #else
 	*** intf.vm: don't know what to do with $n ***

Modified: incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/remote.vm
URL: http://svn.apache.org/viewvc/incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/remote.vm?rev=1149242&r1=1149241&r2=1149242&view=diff
==============================================================================
--- incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/remote.vm (original)
+++ incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/remote.vm Thu Jul 21 15:56:16 2011
@@ -22,9 +22,23 @@
 #set($vfname = "ValueFactory$i")
 #set($intfname = "$i$suffix")
 #set($clname = "Remote$intfname")
+#set($whoType = "Who")
+#set($whoName = "recipient")
+#set($signalPrefix = "_")
+#set($signalSuffix = "Subscribers")
+#set($hasSignals = false)
+#if ($intf.signals( false ).hasNext())
+#set($hasSignals = true)
+#end
 
 package $intf.parent().name();
 
+#if ($hasSignals && $helper.isClient($mc))
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.etch.util.core.Who;
+#end
 #foreach( $n in $intf.iterator() )
 #if($n.isExtern())
 #if($n.hasImport( $helper ))
@@ -43,6 +57,15 @@ public final class $clname extends Remot
 public class $clname extends org.apache.etch.bindings.java.support.RemoteBase implements $intfname
 #end
 {
+#if ($hasSignals && $helper.isClient($mc))
+#foreach( $s in $intf.signals( false ) )
+	/**
+	 * Set holding the clients subscribed for the signal.
+	 */
+	private final Set<$whoType> $signalPrefix$s.getSignalName()${signalSuffix};
+
+#end
+#end
 	/**
 	 * Constructs the $clname.
 	 *
@@ -62,7 +85,49 @@ public class $clname extends org.apache.
 		$v = new ${m.name()}.Remote$z.name()${suffix}( svc, vf );
 #end
 #end
+#if ($hasSignals && $helper.isClient($mc))
+
+#foreach( $s in $intf.signals( false ) )
+		$signalPrefix$s.getSignalName()$signalSuffix = new HashSet<$whoType>();
+#end
+#end
 	}
+#if ($hasSignals && $helper.isClient($mc))
+#foreach( $s in $intf.signals( false ) )
+
+	public boolean _Add$s.getSignalName()Subscriber($whoType subscriber)
+	{
+		synchronized ($signalPrefix$s.getSignalName()${signalSuffix})
+		{
+			return $signalPrefix$s.getSignalName()${signalSuffix}.add(subscriber);
+		}
+	}
+
+	public boolean _Remove$s.getSignalName()Subscriber($whoType subscriber)
+	{
+		synchronized ($signalPrefix$s.getSignalName()${signalSuffix})
+		{
+			return $signalPrefix$s.getSignalName()${signalSuffix}.remove(subscriber);
+		}
+	}
+
+	public boolean _Is$s.getSignalName()Subscriber($whoType subscriber)
+	{
+		synchronized ($signalPrefix$s.getSignalName()${signalSuffix})
+		{
+			return $signalPrefix$s.getSignalName()${signalSuffix}.contains(subscriber);
+		}
+	}
+
+	public Who[] _get$s.getSignalName()Subscribers()
+	{
+		synchronized ($signalPrefix$s.getSignalName()${signalSuffix})
+		{
+			return $signalPrefix$s.getSignalName()${signalSuffix}.toArray(new Who[] {});
+		}
+	}
+#end
+#end
 
 	/**
 	 * {@link _Async} class instance used to hide asynchronous message
@@ -85,13 +150,42 @@ public class $clname extends org.apache.
 #if(!$methodList.contains($n.name().name()))
 #set ( $addMethodListStatus = $methodList.add($n.name().name()))
 #if($n.isOneway())
+#set( $mtdPrefix = "" )
+#if ($n.hasSignal() && $n.isMsgDirClient())
+#set( $mtdPrefix = "_" )
 
-	public final $helper.getTypeName( $n.type() ) $n.name()(
+	public final void $n.name()(
+#set( $sep = "" )
+#foreach( $p in $n.iterator() )
+		$sep$helper.getTypeName( $p.type() ) $p.name()
+#set( $sep = ", " )
+#end
+	)
+	{
+		synchronized( $signalPrefix$n.getMessageSignalName().name()${signalSuffix} )
+		{
+			for ( $whoType subscriber : $signalPrefix$n.getMessageSignalName().name()${signalSuffix} )
+				$mtdPrefix$n.name()(
+#set( $sep = "" )
+#foreach( $p in $n.iterator() )
+					$sep$p.name()
+#set( $sep = ", " )
+#end
+					${sep}subscriber
+				);
+		}
+	}
+#end
+
+	public final $helper.getTypeName( $n.type() ) $mtdPrefix$n.name()(
 #set( $sep = "" )
 #foreach( $p in $n.iterator() )
 		$sep$helper.getTypeName( $p.type() ) $p.name()
 #set( $sep = ", " )
 #end
+#if ($n.hasSignal() && $n.isMsgDirClient())
+		$sep$whoType $whoName
+#end
 	)
 	{
 		org.apache.etch.bindings.java.msg.Message _msg = _newMessage( $vfname.$n.vname( $helper ) );
@@ -100,7 +194,11 @@ public class $clname extends org.apache.
 #end
 		try
 		{
+#if ($n.hasSignal() && $n.isMsgDirClient())
+			_send( _msg, $whoName );
+#else
 			_send( _msg );
+#end
 		}
 		catch ( Exception _e )
 		{

Modified: incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/stub.vm
URL: http://svn.apache.org/viewvc/incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/stub.vm?rev=1149242&r1=1149241&r2=1149242&view=diff
==============================================================================
--- incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/stub.vm (original)
+++ incubator/etch/branches/singlestack/binding-java/compiler/src/main/resources/org/apache/etch/bindings/java/compiler/stub.vm Thu Jul 21 15:56:16 2011
@@ -93,9 +93,13 @@ public class Stub$i$suffix<T extends $i$
 #foreach( $mthd in $intf.iterator() )
 #if ($mthd.isMsgDir($mc))
 #if (!$mthd.isHidden())
-		ValueFactory$i.${mthd.vname( $helper )}.setStubHelper( new StubHelper<$i$suffix>()
+#set( $signalPrefix = "")
+#if ($mthd.isMsgDirServer() && $mthd.hasSignal())
+#set( $signalPrefix = "Base")
+#end
+		ValueFactory$i.${mthd.vname( $helper )}.setStubHelper( new StubHelper<$signalPrefix$i$suffix>()
 		{
-			public final void run( DeliveryService _svc, $i$suffix _obj, Who _sender, Message _msg ) throws Exception
+			public final void run( DeliveryService _svc, $signalPrefix$i$suffix _obj, Who _sender, Message _msg ) throws Exception
 			{
 #if (!$mthd.isOneway())
 				final Message _rmsg = _msg.reply();
@@ -145,6 +149,9 @@ public class Stub$i$suffix<T extends $i$
 #end
 #set( $sep = ", " )
 #end
+#if ($mthd.isMsgDirServer() && $mthd.hasSignal())
+						${sep}_sender
+#end
 #if ($mthd.hasReturn())
 					)
 #end

Modified: incubator/etch/branches/singlestack/binding-java/runtime/src/main/java/org/apache/etch/bindings/java/support/RemoteBase.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/singlestack/binding-java/runtime/src/main/java/org/apache/etch/bindings/java/support/RemoteBase.java?rev=1149242&r1=1149241&r2=1149242&view=diff
==============================================================================
--- incubator/etch/branches/singlestack/binding-java/runtime/src/main/java/org/apache/etch/bindings/java/support/RemoteBase.java (original)
+++ incubator/etch/branches/singlestack/binding-java/runtime/src/main/java/org/apache/etch/bindings/java/support/RemoteBase.java Thu Jul 21 15:56:16 2011
@@ -23,6 +23,7 @@ package org.apache.etch.bindings.java.su
 import org.apache.etch.bindings.java.msg.Message;
 import org.apache.etch.bindings.java.msg.Type;
 import org.apache.etch.bindings.java.msg.ValueFactory;
+import org.apache.etch.util.core.Who;
 import org.apache.etch.util.core.io.Transport;
 import org.apache.etch.util.core.io.Transport.WaitDown;
 import org.apache.etch.util.core.io.Transport.WaitUp;
@@ -78,6 +79,18 @@ public class RemoteBase
 	}
 	
 	/**
+	 * Sends the message to the recipient, but does not wait for any response.
+	 * 
+	 * @param msg the message to send
+	 * @param receiver the message receiver
+	 * @throws Exception if there is a problem sending
+	 */
+	public void _send( Message msg, Who receiver ) throws Exception
+	{
+		_svc.transportMessage( receiver, msg );
+	}
+
+	/**
 	 * Sends the message which begins a call sequence.
 	 * 
 	 * @param msg the message to send.

Modified: incubator/etch/branches/singlestack/util/src/main/java/org/apache/etch/util/core/io/InetWho.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/singlestack/util/src/main/java/org/apache/etch/util/core/io/InetWho.java?rev=1149242&r1=1149241&r2=1149242&view=diff
==============================================================================
--- incubator/etch/branches/singlestack/util/src/main/java/org/apache/etch/util/core/io/InetWho.java (original)
+++ incubator/etch/branches/singlestack/util/src/main/java/org/apache/etch/util/core/io/InetWho.java Thu Jul 21 15:56:16 2011
@@ -70,4 +70,25 @@ public class InetWho implements Who
 	{
 		return this.addr.equals( addr ) && this.port == port;
 	}
+
+	@Override
+	public boolean equals( Object obj ) {
+		if (obj instanceof InetWho) {
+			InetWho whoObj = (InetWho) obj;
+			
+			return matches(whoObj.addr, whoObj.port);
+		}
+
+		return super.equals(obj);
+	}
+
+	@Override
+	public int hashCode() {
+		return addr.hashCode() + port;
+	}
+
+	@Override
+	public String toString() {
+		return "InetWho(" + addr.getHostAddress() + ":" + port + ")";
+	}
 }
\ No newline at end of file