Skip to content

Commit

Permalink
Added README.md information and ALMI description
Browse files Browse the repository at this point in the history
Adde ping pong almi example
  • Loading branch information
MatteoBattilana committed Apr 21, 2019
1 parent 78b7b38 commit 18c56e4
Show file tree
Hide file tree
Showing 13 changed files with 465 additions and 205 deletions.
83 changes: 82 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,86 @@
# ALMI (Abstraction Layer for Multiserver Infrastructure)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.matteobattilana/almi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.matteobattilana/almi)
[![CircleCI](https://circleci.com/gh/MatteoBattilana/ALMI.svg?style=svg)](https://circleci.com/gh/MatteoBattilana/ALMI)

## Description
ALMI is a JAVA multiserver framework for remote method calls management based on Netty and Jackson serialization, that adds an abstraction layer for multiserver communication.
ALMI is a Java multiserver framework for remote method calls management based on Netty and Jackson serialization, that adds an abstraction layer for multiserver communication.

This framework will semplify the cluster management, making methods accessibile from other server, that has ALMI running on a node in the cluster.

## Setup
Add ALMI dependencies in your pom.xml or eventually, go to the [Maven Repository](https://search.maven.org/artifact/com.matteobattilana/almi/0.1.0/jar) and download the jar library file.

```xml
<dependencies>
...
<dependency>
<groupId>com.matteobattilana</groupId>
<artifactId>almi</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>
```

## Simple usage

The following code will instantiate an ALMI server that is listening on the 8888 port (if not set, it will use the one described in the [Default configuration](#Default configuration) section).

```java
Almi server = AlmiBootstrap.bootstrap()
.withPort(8888)
.withRemoteCallTimeout(2000)
.withMethodsMapper(new MethodsMapper()
{
@Override
public void configure()
throws Exception
{
addMethods(
bindStatic(Calculator.class).method("execute", double.class, Calculator.Operation.class, double.class).withDefaultName(),
bind(new Calculator()).method(Calculator.class.getMethod("sqrt", double.class)).withName("positiveSqrt")
);
}
})
.start();
```

### MethodsMapper
MethodsMapper will let you define the mapping beetwen the local method implementation and its remote name. This is used to make methods accessibile from other ALMI server, running on a node in the cluster.

A MethodsMapper can be defined in-line as the one in previous example, or in a specific class. The `addMethods` will configure the methods passed as arguments, in order to expose them.
```java
public class MethodMapperImpl extends MethodsMapper
{
private final ClientInformation mInstance1;

public MethodMapperImpl(
ClientInformation instance1
)
{
mInstance1 = instance1;
}

@Override
public void configure()
throws Exception
{
addMethods(
bind(mInstance1).method(ClientInformation.class.getMethod("helloWorld")).withDefaultName(),
bindStatic(ClientInformation.class).method(ClientInformation.class.getMethod("ping")).withDefaultName()
);
}
}
```


## Configuration
### Default configuration
The defaul configuration loaded from static constants from the Constants.java:

```java
public static final int DEFAULT_PORT = 8888;
public static final int DEFAULT_CONNECTION_TIMEOUT = 10000;
public static final int DEFAULT_PROMISE_TIMEOUT = 10000;
public static final String DEFAULT_THREAD_NAME = "almi-service";
public static final String DEFAULT_ADDRESS = "localhost";
```
4 changes: 2 additions & 2 deletions examples/calculator/AlmiCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import exceptions.InvisibleWrapperException;
import socket.Almi;
import socket.bootstrap.DefaultAlmiBootstrap;
import socket.bootstrap.AlmiBootstrap;
import socket.bootstrap.MethodsMapper;

import java.util.Arrays;
Expand All @@ -13,7 +13,7 @@ public class AlmiCalculator
public static void main(String[] args)
throws Exception
{
Almi server = DefaultAlmiBootstrap.bootstrap()
Almi server = AlmiBootstrap.bootstrap()
.withPort(8888)
.withRemoteCallTimeout(2000)
.withMethodsMapper(new MethodsMapper()
Expand Down
4 changes: 2 additions & 2 deletions examples/clientinformation/ClientInformation.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package clientinformation;

import socket.Almi;
import socket.bootstrap.DefaultAlmiBootstrap;
import socket.bootstrap.AlmiBootstrap;
import socket.bootstrap.MethodsMapper;

import java.lang.management.ManagementFactory;
Expand All @@ -11,7 +11,7 @@ public class ClientInformation implements Methods
public static void main(String[] args)
throws Exception
{
Almi server = DefaultAlmiBootstrap.bootstrap()
Almi server = AlmiBootstrap.bootstrap()
.withPort(8888)
.withThreadName("ClientInformation-ALMI-server")
.withRemoteCallTimeout(2000)
Expand Down
33 changes: 33 additions & 0 deletions examples/pingpong/AlmiPingPong.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package pingpong;

import socket.Almi;
import socket.bootstrap.AlmiBootstrap;

import java.util.Arrays;
import java.util.Collections;

public class AlmiPingPong
{
public static void main(String[] args)
throws Exception
{
Almi server = AlmiBootstrap.bootstrap()
.withPort(8888)
.withRemoteCallTimeout(2000)
.withMethodsMapper(new MethodsMapperImpl(new PingPong()))
.start();

PingPong.State state = PingPong.State.PING;
for(int i = 0; i < 10; i++)
{
state = server.callMethod(
"localhost",
8888,
"ping",
Collections.singletonList(state)
);
System.out.println(state);
}
server.stop();
}
}
22 changes: 22 additions & 0 deletions examples/pingpong/MethodsMapperImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package pingpong;

import socket.bootstrap.MethodsMapper;

public class MethodsMapperImpl extends MethodsMapper
{
private final PingPong mPingPong;

public MethodsMapperImpl(PingPong pingPong)
{
mPingPong = pingPong;
}

@Override
public void configure()
throws Exception
{
addMethods(
bind(mPingPong).method("getReponse", PingPong.State.class).withName("ping")
);
}
}
37 changes: 37 additions & 0 deletions examples/pingpong/PingPong.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package pingpong;

public class PingPong
{
public enum State
{
PING("ping"),
PONG("pong"),
UNKNOWN("");

private final String mState;

State(String state)
{
mState = state;
}

@Override
public String toString()
{
return mState;
}
}

public State getReponse(State request)
{
switch(request)
{
case PING:
return State.PONG;
case PONG:
return State.PING;
default:
return State.UNKNOWN;
}
}
}
98 changes: 95 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<groupId>com.matteobattilana</groupId>
<artifactId>com.matteobattilana</artifactId>
<version>1.0-SNAPSHOT</version>
<artifactId>almi</artifactId>
<version>0.1.1</version>
<build>
<plugins>
<plugin>
Expand All @@ -19,7 +19,6 @@
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -29,8 +28,101 @@
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<packaging>jar</packaging>
<name>ALMI (Abstraction Layer for Multiserver Infrastructure)</name>
<description>ALMI is a Java multiserver framework for remote method calls management based on Netty and Jackson serialization, that adds an abstraction layer for multiserver communication.</description>
<url>https://github.com/MatteoBattilana/ALMI</url>
<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>

<profiles>
<profile>
<id>release</id>
</profile>
</profiles>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<scm>
<connection>scm:git:git://github.com/MatteoBattilana/ALMI.git</connection>
<developerConnection>scm:git:ssh://github.com/MatteoBattilana/ALMI.git</developerConnection>
<url>http://github.com/MatteoBattilana/ALMI/tree/master</url>
</scm>

<developers>
<developer>
<name>Matteo Battilana</name>
<email>matteo@matteobattilana.com</email>
<organization>http://matteobattilana.com</organization>
<organizationUrl>http://matteobattilana.com</organizationUrl>
</developer>
</developers>

<dependencies>
<!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
Expand Down
Loading

0 comments on commit 18c56e4

Please sign in to comment.