Conditional annotations

7 views
Skip to first unread message

Jim Marino

unread,
Oct 14, 2015, 10:24:14 AM10/14/15
to fabric3
Hi,

Based on some conversations with Tomas and Stano a few weeks back, I think we have come up with a simple replacement for binding.sca. As some background, the issue with binding.sca is that it complicates the runtime and (more importantly) has only limited use in practice. Specifically, most remote communications require the clients and services to be tuned based on application requirements, for example, how dispatching is performed to transports, buffer depth, etc. With binding.sca there is no mechanism for doing this conveniently. It's a "one size fits all" approach in that all remote communications share the same configuration parameters.

One way to handle this would be to provide more configuration for binding.sca but this just adds a layer of indirection that makes the application setup more difficult to follow. In talking to Tomas and Stano, one of the benefits of binding.sca that came up is the ability to transparently switch between bindings and from local to remote transports. So, we came up with an approach that I'm going to call "conditional annotations".  Components and references can now specify what runtime environments they should be applied to. For example, a binding is to be applied when the runtime is run in "production" mode but ignored when run in "test" mode. Since Java 8 supports repeatable annotations, components and references can use the same binding annotation multiple times for different environments. This satisfies the binding.sca use case of transparently changing communications as well as allowing specific configuration for clients and services. 

On services binding annotations use the "environments" property to specify one or more runtime environments they are activated in:
  
@ZeroMQ(environments = {"test", "production"})
@Component
public class RemoteServiceImpl implements RemoteService {

    //....
}

And on references:

public class ClientService {

    @ZeroMQ(target = "RemoteService", environments = {"test","production"})  
    protected RemoteService remoteService;

   //...

}

In the above example, the ZeroMQ binding is used when the runtime is run in "test" and "production" but not in "development", where a local connection is used.
 
These annotations can even be used with the meta-annotation support we added. For example:

@ZeroMQ(environments = {"test", "production"})
@interface SwappableTransport {

}

@SwappableTransport
@Component
public class RemoteServiceImpl implements RemoteService {

    //....
}

I'm interested in feedback and testing of this feature if people have time.

Jim


Reply all
Reply to author
Forward
0 new messages