Coder Social home page Coder Social logo

fritzprix / yarmi Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 43.88 MB

yet-another RMI Framework for Java

License: Apache License 2.0

Java 95.62% Shell 3.02% Batchfile 1.36%
rmi rmi-framework rmi-server rmi-registry java android java-rmi android-rmi remote-method-invocation

yarmi's Introduction

logo

RMI (Remote Method Invocation) framework supporting service discovery out-of-box among devices within same network considering IOT(internet of device) proof-of-concept project

Codacy Badge Build Status

Features

  1. Zero configuration for service integration based on RMI and Service Discovery
  2. Simple APIs

discover and request service with just a few API calls

  1. Support large blob as method parameter or response

yarmi supports blob exchange between client and server by default with BlobSession which exposes familiar read / write APIs

How-To

Using with Maven

  1. Add Maven Repository
<repositories>
    <repository>
        <id>yarmi-core</id>
        <name>yarmi</name>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <url>https://raw.githubusercontent.com/fritzprix/yarmi/releases</url>
    </repository>
</repositories>
  1. Add dependency
<dependencies>
        <dependency>
            <groupId>net.doodream</groupId>
            <artifactId>yarmi-core</artifactId>
            <version>0.1.1</version>
        </dependency>
            <dependency>
                <groupId>net.doodream.yarmi</groupId>
                <artifactId>sdp-mdns</artifactId>
                <version>0.1.1</version>
            </dependency>
</dependencies>

Using with Gradle

  1. Add Repository
allprojects {
    repositories {
        ...
        maven {
            url 'https://raw.githubusercontent.com/fritzprix/yarmi/releases'
        }
        maven {
            url 'https://raw.githubusercontent.com/fritzprix/yarmi/snapshots'
        }
        ...
    }
}
  1. Add Dependency
dependencies {
...
    implementation 'net.doodream:yarmi-core:0.1.1'
    implementation 'net.doodream.yarmi:sdp-mdns:0.1.1'
    implementation 'org.jmdns:jmdns:3.5.1'

...
}

Build Service (Server)

  1. Declare controller stubs with RMIExpose annotation
public interface TestController {

    @RMIExpose
    Response<String> echo(String message);
} 
  1. Implement Controller
public class TestControllerImpl implements TestController {


    @Override
    public Response<String> echo(String message) {
        return Response.success(message);
    }
}  
  1. Declare your service with route configuration
@Service(name = "test-service",
         provider = "com.example",
         params = {
            @AdapterParam(key=TcpServiceAdapter.PARAM_PORT, value = "6644")
         })
public class TestService {

    @Controller(path = "/test", version = 1, module = TestControllerImpl.class)
    TestController controller;
}
  1. Start service & advertise it
    final RMIService service = RMIService.create(TestService.class);
    final ServiceRegistry registry = MDnsServiceRegistry.create();
    
    service.listen();
    registry.register(service);
    registry.start();

Build Client

  1. Discover service & create client
    // build target service information
    final ServiceDiscovery discovery = MDnsServiceDiscovery.create();
    discovery.start(TestService.class, new ServiceDiscoveryListener() {
        @Override
        public void onDiscoveryStarted() {
            // discovery started
        }

        @Override
        public void onServiceDiscovered(RMIServiceInfo service) {
            // new service discovered
            Object client = RMIClient.create(servce, TestService.class, new Class[] {
                    TestController.class
            });
            // cast client proxy into interface of interest
            TestController controller = (TestController) client;
            // and use it 
            Response<String> response = controller.echo("Hello");
            if(response.isSucessful()) {
                // successfully RMI handled and response received successfully
                System.out.println(response.getBody());
            }
        }

        @Override
        public void onDiscoveryFinished(int i, Throwable throwable) {
            // service discovery finished
        }
    });

License

Apache License, Version 2.0

yarmi's People

Contributors

area55git avatar dependabot[bot] avatar fritzprix avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

area55git

yarmi's Issues

HaRMIClient raises exception in invoking call proxy

method invoke with null argument was equivalent to invoke with no argument in Java8 (no problem with no-arg method)
method invoke with null argument for no-arg method raise IllegalArgumentException in Java7

originally method invocation has been directly performed by calling RMIClient::invoke method and it was changed to calling call proxy of RMIClient later. however, the invocation has not reflected the change

key for method lookup is not unique

unique key is generated by code below (com.doodream.rmovjs.model.Endpoint)

final String methodLookupKey = String.format("%x%x%x", rmiMethod.hashCode(), controller.path().hashCode(), paramUnique.hashCode()).toUpperCase();

which was actually generate same keys for methods whose RMIMethod declared / parameter / enclosing controller are same.

blobsessin closed with remaining unread data

Data missed at the end of the stream happens quite often in multi threading situation

  • PipedInput/Outputstream is used for delivering the incoming data from the network (socket) to the another read end point.
  • each writer & reader is performed at different thread
  • read() returns -1 when the writer thread is dead
  • reader finishes the read loop

If alternative (spf4j) is used the issue has been resolved.

Logo Proposal for Yarmi

Hi, I'm a graphic designer and I like to collaborate with open source projects. Do you know that the graphic image of a project is very important? thinking about it I would like to design a logo for your Project Yarmi.

I will be pleased to collaborate with you.

JUnit testing is failing on Travis CI

maven test is failing on Travis CI environment, which is not reproduced on my own machine.

java.lang.NullPointerException
at com.doodream.rmovjs.test.ServiceNoReplyTest.startServer(ServiceNoReplyTest.java:28)
[INFO] Running com.doodream.rmovjs.test.EchoBackTest
[ERROR] Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0 s <<< FAILURE! - in com.doodream.rmovjs.test.EchoBackTest
[ERROR] com.doodream.rmovjs.test.EchoBackTest Time elapsed: 0 s <<< ERROR!
java.lang.NullPointerException
at com.doodream.rmovjs.test.EchoBackTest.startServer(EchoBackTest.java:35)
[ERROR] com.doodream.rmovjs.test.EchoBackTest Time elapsed: 0 s <<< ERROR!
java.lang.NullPointerException
at com.doodream.rmovjs.test.EchoBackTest.stopServer(EchoBackTest.java:43)

SimpleServiceDiscovery doesn't work across the hosts

SimpleServiceDiscovery & SimpleServiceAdvertiser is tested on single host so far, there was no problem. but testing between two host it doesn't work. tried to modify udp related code as below but still doesn't work

creating packet

return new DatagramPacket(infoByteString, infoByteString.length, Inet4Address.getByName("255.255.255.255"), BROADCAST_PORT);

sending it

        DatagramSocket socket = new DatagramSocket();
        socket.setBroadcast(true);
        socket.send(datagramPacket);
        socket.close();

receiver

       DatagramSocket serviceBroadcastSocket = new DatagramSocket(SimpleServiceAdvertiser.BROADCAST_PORT);
       serviceBroadcastSocket.setBroadcast(true);

receiving

        byte[] buffer = new byte[64 * 1024];
        Arrays.fill(buffer, (byte) 0);
        DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
        serviceBroadcastSocket.receive(packet);

and tcpdump shows broadcast packet dest address of 255.255.255.255

slim down dependencies

remove libraries widely adopted in developing application to prevent unnecessary dependency conflict.

list

  • gson
  • guava
  • rxjava

RMIClient::create causes exception on Android K

W/System.err: Caused by: java.lang.NoSuchMethodError: No virtual method getParameterCount()I in class Ljava/lang/reflect/Constructor; or its super classes (declaration of 'java.lang.reflect.Constructor' appears in /system/framework/core-libart.jar)
W/System.err: at com.doodream.rmovjs.net.tcp.TcpServiceAdapter$3.test(TcpServiceAdapter.java:45)
W/System.err: at com.doodream.rmovjs.net.tcp.TcpServiceAdapter$3.test(TcpServiceAdapter.java:42)

Handling recursive type parameter in serialization

class serialization performed with Class.getName() -> Class.forName()
in this way, there are some cases out of handle

  • return type or any parameter using type parameter in recursive like Response<List>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.