[Miwi-middleware] KIARA example for Java

Dmitri Rubinstein rubinstein at cs.uni-saarland.de
Wed Oct 1 14:13:21 CEST 2014


Hi,

I modified your code to show the DFKI approach. Currently it is just for 
the client, quick and dirty. Our application example is pretty like 
yours just we start with this (see ClientExampleDFKI.java):

Context context = Kiara.createContext();
Connection connection = context.openConnection("tcp://127.0.0.1:8080");
Calculator proxy = connection.getServiceInterface(Calculator.class);

The magic is in getServiceInterface:

public <T> T getServiceInterface(Class<T> interfaceClass) throws Exception {
   String proxyClassName = interfaceClass.getName()+"Proxy";
   Class<?> proxyClass = Class.forName(proxyClassName);
   if (!interfaceClass.isAssignableFrom(proxyClass))
     throw new RuntimeException("Proxy class "+proxyClass+" does not 
implement interface "+interfaceClass);
   Constructor<?> proxyConstr = 
proxyClass.getConstructor(Serializer.class, ProxyTransport.class);
   proxyConstr.setAccessible(true);
   return interfaceClass.cast(proxyConstr.newInstance(serializer, 
transport));
}

So mostly our API is just a higher abstraction level.

Since I am not familiar with Ant and Eclipse is not automatically 
imports it I recreated project with Maven. Maven is also the de facto 
standard for Java and is directly supported by main IDEs (Eclipse, 
NetBeans, IntelliJ). You need to install Maven and then run "mvn 
install" in kiara_java_mod directory to build everything. "mvn clean" 
will do a cleanup. Archive also includes Eclipse project and .git 
repository so you can track my changes. Shell scripts for running 
example are included as well.

Best,

Dmitri

On 10/01/14 11:31, Ricardo Gonzalez Moreno wrote:
> Hi all,
>
> As it was proposed, yesterday I wrote an example. It is fully functional
> and contains a client and a server that implement the following IDL:
>
>     *service* Calculator
>     {
>     long add(long param1, long param2);
>
>     long subtract(long param1, long param2);
>     };
>
>
> This example shows a possible future API, although the naming is not
> final. I tried to make it simple and user-friendly. This API is very
> easy to implement, and I developed a complete working example within one
> day.
>
> To develop a client application, the user should select the network
> transport and the serialization mechanism. Then he has to create the
> proxy to connect to the remote service.
>
>     /// Create custom transport, serializer and the proxy./
>     ProxyTransport transport = *new *TCPProxyTransport("127.0.0.1",8080);
>     Serializer ser = *new *Cdr();
>     CalculatorProxy *proxy*= *new *CalculatorProxy(ser, transport);
>
>
> After these steps, he can call the remote methods.
>
>
>     /// Call 'add' method./
>     ret = *proxy*.add(param1, param2);
>
>
> To develop a server application, the user should select the network
> transport and the serialization mechanism. Then he has to invoke a
> server instance.
>
>     ServerTransport transport = *new* TCPServerTransport(8080);
>     Serializer serializer = *new* Cdr();
>     Server server = *new* Server(serializer, transport);
>
>
> After these steps, he can add his servants and run the server.
>
>     Servant *servant* = *new* CalculatorServantExample();
>     server.addService(*servant*);
>     server.serve();
>
>
> This source code the user has to write is located in the directory
> 'user_src'.
> Also this example contains source code that should be generated by a IDL
> compiler. It is located in the folder 'gen_src'. The KIARA core source
> code is located in 'kiara_src'. You can see the code is pretty
> straightforward and just 20-30 lines of generated code do all the
> necessary tasks.
>
> This example can be compiled using 'ant', although I already provide the
> bytecode. The archive contains two bash script to execute the client
> (clientexample.sh) and the server (serverexample.sh)
>
>
> _______________________________________________
> Miwi-middleware mailing list
> Miwi-middleware at lists.fi-ware.org
> https://lists.fi-ware.org/listinfo/miwi-middleware
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: kiara_java_mod_2014-10-01.tar.gz
Type: application/gzip
Size: 49522 bytes
Desc: not available
URL: <https://lists.fiware.org/private/miwi-middleware/attachments/20141001/2acea516/attachment.bin>


More information about the Miwi-middleware mailing list

You can get more information about our cookies and privacy policies clicking on the following links: Privacy policy   Cookies policy