Skip to content

Commit

Permalink
Release (#9)
Browse files Browse the repository at this point in the history
* Updated version in readme, added mvn central badge, fix typo

* Added multiply example

* Optimized all imports

* Log errors thrown by implementations (#8)

* Version bump

---------

Co-authored-by: Duckelekuuk <[email protected]>
Co-authored-by: Duckelekuuk <[email protected]>
  • Loading branch information
3 people authored Nov 10, 2023
1 parent b4cb9b6 commit 4ce6ca4
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 24 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img height="150" src="https://github.com/pixelib/Meteor/assets/10709682/d2a36e0a-38d5-43b7-a33b-600834559e46" />
</p>

# Meteor ![branches](.github/badges/branches.svg) ![jacoco coverage](.github/badges/jacoco.svg)
# Meteor ![Maven Central](https://img.shields.io/maven-central/v/dev.pixelib.meteor/meteor-parent) ![branches](.github/badges/branches.svg) ![jacoco coverage](.github/badges/jacoco.svg)
> A general-purpose Java RPC library that plugs in like magic
Meteor is designed to fill the (physical) gap between application instances and remote services where applications need to interface with a service that may be available locally or be provided by a remote JVM instance.
Expand All @@ -12,7 +12,7 @@ It allows you to write your application against your interface as if it's local
<img src=".github/assets/flow.png" />
</p>

> *Note that this diagram ommits certain parts, like scheduling/threading and abstracted serailization layers to make it more readable.*
> *Note that this diagram omits certain parts, like scheduling/threading and abstracted serialization layers to make it more readable.*
# Installation
Meteor comes by default with a local loopback transport.
Expand All @@ -21,7 +21,7 @@ Meteor is available on Maven Central, and can be installed by adding the followi
<dependency>
<groupId>dev.pixelib.meteor</groupId>
<artifactId>meteor-core</artifactId>
<version>1.0.0</version>
<version>1.0.2</version>
</dependency>
```

Expand All @@ -32,7 +32,7 @@ You can install the Redis transport by adding the following dependency to your `
<dependency>
<groupId>dev.pixelib.meteor.transport</groupId>
<artifactId>meteor-jedis</artifactId>
<version>1.0.0</version>
<version>1.0.2</version>
</dependency>
```

Expand Down Expand Up @@ -105,7 +105,7 @@ A full performance analysis can be found [here](PERFORMANCE.md)

# Design considerations
### To queue or not to queue
The library itself is unopinionated about transport and thus execution.
The library itself is un opinionated about transport and thus execution.
It's up to the specific transport implementation to decide whether a fan-out or queueing strategy is appropriate. The default Redis implementation uses a normal broadcast, meaning that all invocations will be executed on all nodes which provide an implementation (but only the first return value is returned to the invoker function). Other implementations may use a more sophisticated queueing mechanism, allowing implementation instances to only process a subset of the invocations.

### Error handling
Expand All @@ -115,5 +115,5 @@ Invocations leading to an exception on the implementation are considered as not
Each Meteor instance uses its own internal thread pool for invocations against implementations. Invocations are queued up (in order of invocation time) if an implementation is busy. The thread pool size can be configured through the `RpcOptions`, and defaults to `1`.

### To serialize or not to serialize
The library itself is unopinionated about serialization.
The library itself is un opinionated about serialization.
GSON gets used by default, but you can use any other serialization library you want, as long as it can serialize and deserialize generic types with another fallback method for unknown types.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static void main(String[] args) throws Exception{

MathAdd mathAdd = meteor.registerProcedure(MathAdd.class);
MathSubstract mathSubstract = meteor.registerProcedure(MathSubstract.class);
MathMultiply mathMultiply = meteor.registerProcedure(MathMultiply.class);

// register an implementation, invocations will be dispatched to this object.
// implementations will be registered under all interfaces they implement
Expand All @@ -21,6 +22,9 @@ public static void main(String[] args) throws Exception{
int addResult = mathAdd.add(1, 2, 3, 4, 5);
System.out.println("1 + 2 + 3 + 4 + 5 = " + addResult);

int multiResult = mathMultiply.multiply(5, 5);
System.out.println("5 * 5 = " + multiResult);

meteor.stop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static void main(String[] args) throws Exception{

MathAdd mathAdd = meteor.registerProcedure(MathAdd.class);
MathSubstract mathSubstract = meteor.registerProcedure(MathSubstract.class);
MathMultiply mathMultiply = meteor.registerProcedure(MathMultiply.class);

// register an implementation, invocations will be dispatched to this object.
// implementations will be registered under all interfaces they implement
Expand All @@ -22,6 +23,9 @@ public static void main(String[] args) throws Exception{
int addResult = mathAdd.add(1, 2, 3, 4, 5);
System.out.println("1 + 2 + 3 + 4 + 5 = " + addResult);

int multiResult = mathMultiply.multiply(5, 5);
System.out.println("5 * 5 = " + multiResult);

meteor.stop();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.pixelib.meteor.base;

import dev.pixelib.meteor.base.interfaces.SubscriptionHandler;
import dev.pixelib.meteor.base.enums.Direction;
import dev.pixelib.meteor.base.interfaces.SubscriptionHandler;

import java.io.Closeable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;

public class LoopbackTransport implements RpcTransport {

private final Map<Direction, List<SubscriptionHandler>> onReceiveFunctions = new HashMap<>();
private final Map<Direction, List<SubscriptionHandler>> onReceiveFunctions = new EnumMap<>(Direction.class);

/**
* @param bytes the bytes to send
* bytes given should already been considered as a packet, and should not be further processed by the transport implementation
* bytes given should already been considered as a packet, and should1not be further processed by the transport implementation
* this particular implementation will call all the onReceive functions, and stop if one of them returns HANDLED
* no actual sending is done, as this is a loopback transport meant for testing
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import dev.pixelib.meteor.base.RpcSerializer;
import dev.pixelib.meteor.base.RpcTransport;
import dev.pixelib.meteor.base.defaults.GsonSerializer;
import dev.pixelib.meteor.core.proxy.ProxyInvocHandler;
import dev.pixelib.meteor.core.proxy.MeteorMock;
import dev.pixelib.meteor.core.proxy.ProxyInvocHandler;
import dev.pixelib.meteor.core.trackers.IncomingInvocationTracker;
import dev.pixelib.meteor.core.trackers.OutgoingInvocationTracker;
import dev.pixelib.meteor.core.transport.TransportHandler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.pixelib.meteor.core.proxy;

import dev.pixelib.meteor.core.transport.packets.InvocationDescriptor;
import dev.pixelib.meteor.core.trackers.OutgoingInvocationTracker;
import dev.pixelib.meteor.core.transport.packets.InvocationDescriptor;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
import dev.pixelib.meteor.base.enums.Direction;
import dev.pixelib.meteor.core.executor.ImplementationWrapper;
import dev.pixelib.meteor.core.trackers.IncomingInvocationTracker;
import dev.pixelib.meteor.core.trackers.OutgoingInvocationTracker;
import dev.pixelib.meteor.core.transport.packets.InvocationDescriptor;
import dev.pixelib.meteor.core.transport.packets.InvocationResponse;
import dev.pixelib.meteor.core.trackers.OutgoingInvocationTracker;

import java.io.Closeable;
import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;

public class TransportHandler implements Closeable {

private final Logger logger = Logger.getLogger(TransportHandler.class.getSimpleName());
private final RpcSerializer serializer;
private final RpcTransport transport;
private final IncomingInvocationTracker incomingInvocationTracker;
Expand Down Expand Up @@ -91,8 +94,8 @@ private boolean handleInvocationRequest(byte[] bytes) throws ClassNotFoundExcept
Object response = matchedImplementation.invokeOn(invocationDescriptor, invocationDescriptor.getReturnType());
InvocationResponse invocationResponse = new InvocationResponse(invocationDescriptor.getUniqueInvocationId(), response);
transport.send(Direction.METHOD_PROXY, invocationResponse.toBytes(serializer));
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (Throwable e) {
logger.log(Level.SEVERE, "An error occurred while invoking a method", e);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import dev.pixelib.meteor.core.transport.packets.InvocationDescriptor;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class LogicTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.pixelib.meteor.core;

import dev.pixelib.meteor.base.defaults.LoopbackTransport;
import org.junit.jupiter.api.Test;
import dev.pixelib.meteor.core.utils.MathFunctions;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Proxy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import dev.pixelib.meteor.base.defaults.GsonSerializer;
import dev.pixelib.meteor.base.defaults.LoopbackTransport;
import dev.pixelib.meteor.base.errors.InvocationTimedOutException;
import dev.pixelib.meteor.core.transport.packets.InvocationDescriptor;
import dev.pixelib.meteor.core.trackers.OutgoingInvocationTracker;
import dev.pixelib.meteor.core.transport.packets.InvocationDescriptor;
import dev.pixelib.meteor.core.transport.packets.InvocationResponse;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.pixelib.meteor.core.trackers;

import dev.pixelib.meteor.core.executor.ImplementationWrapper;
import org.junit.jupiter.api.Test;
import dev.pixelib.meteor.core.utils.MathFunctions;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import dev.pixelib.meteor.base.defaults.GsonSerializer;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

class InvocationDescriptorTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import java.util.UUID;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

class InvocationResponseTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import redis.clients.jedis.Connection;
import redis.clients.jedis.JedisPool;

import java.util.Base64;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</modules>

<properties>
<revision>1.0.0-localbuild</revision>
<revision>1.0.2-localbuild</revision>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down

0 comments on commit 4ce6ca4

Please sign in to comment.