Skip to content

Commit

Permalink
Readme fix (#170)
Browse files Browse the repository at this point in the history
* Fixes readme to provide new framedelegates

* Fixes back to non-lambda form
  • Loading branch information
StrongestNumber9 authored May 15, 2024
1 parent 1b336fe commit ef15554
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 51 deletions.
20 changes: 3 additions & 17 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,13 @@ public class ReadmeTest {
};
/*
* DefaultFrameDelegate accepts Consumer<FrameContext> for processing syslog frames
*/
DefaultFrameDelegate frameDelegate = new DefaultFrameDelegate(syslogConsumer);
/*
* Same instance of the frameDelegate is shared with every connection
* New instance of the frameDelegate is provided for every connection
*/
Supplier<FrameDelegate> frameDelegateSupplier = new Supplier<FrameDelegate>() {
@Override
public FrameDelegate get() {
System.out.println("Providing frameDelegate for a connection");
return frameDelegate;
return new DefaultFrameDelegate(syslogConsumer);
}
};
Expand Down Expand Up @@ -163,6 +157,7 @@ public class ReadmeTest {
* Send Hello, World! via rlp_01
*/
new ExampleRelpClient(listenPort).send("Hello, World!");
new ExampleRelpClient(listenPort).send("Hello, World again!");
/*
* Stop eventLoop
Expand All @@ -180,15 +175,6 @@ public class ReadmeTest {
}
System.out.println("server stopped at port <" + listenPort + ">");
/*
* Close the frameDelegate
*/
try {
frameDelegate.close();
}
catch (Exception e) {
throw new RuntimeException(e);
}
executorService.shutdown();
}
}
Expand Down
20 changes: 3 additions & 17 deletions src/test/java/com/teragrep/rlp_03/readme/ReadmeDeferredTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,11 @@ public void close() {
relpCommandConsumerMap.put(RelpCommand.SYSLOG, syslogRelpEvent);

/*
* Register the commands to the DefaultFrameDelegate
*/
FrameDelegate frameDelegate = new DefaultFrameDelegate(relpCommandConsumerMap);

/*
* Same instance of the frameDelegate is shared with every connection, BlockingQueues are thread-safe
* New instance of the frameDelegate is provided for every connection
*/
Supplier<FrameDelegate> frameDelegateSupplier = () -> {
System.out.println("Providing frameDelegate for a connection");
return frameDelegate;
return new DefaultFrameDelegate(relpCommandConsumerMap);
};

/*
Expand Down Expand Up @@ -171,6 +166,7 @@ public void close() {
* Send Hello, World! via rlp_01
*/
new ExampleRelpClient(listenPort).send("Hello, Deferred World!");
new ExampleRelpClient(listenPort).send("Hello, Deferred World again!");

/*
* Stop eventLoop
Expand All @@ -188,16 +184,6 @@ public void close() {
throw new RuntimeException(interruptedException);
}

/*
* Close the frameDelegate
*/
try {
frameDelegate.close();
}
catch (Exception e) {
throw new RuntimeException(e);
}

/*
* Stop the deferred processing thread
*/
Expand Down
20 changes: 3 additions & 17 deletions src/test/java/com/teragrep/rlp_03/readme/ReadmeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,13 @@ public synchronized void accept(FrameContext frameContext) {
};

/*
* DefaultFrameDelegate accepts Consumer<FrameContext> for processing syslog frames
*/
DefaultFrameDelegate frameDelegate = new DefaultFrameDelegate(syslogConsumer);

/*
* Same instance of the frameDelegate is shared with every connection
* New instance of the frameDelegate is provided for every connection
*/
Supplier<FrameDelegate> frameDelegateSupplier = new Supplier<FrameDelegate>() {

@Override
public FrameDelegate get() {
System.out.println("Providing frameDelegate for a connection");
return frameDelegate;
return new DefaultFrameDelegate(syslogConsumer);
}
};

Expand Down Expand Up @@ -141,6 +135,7 @@ public FrameDelegate get() {
* Send Hello, World! via rlp_01
*/
new ExampleRelpClient(listenPort).send("Hello, World!");
new ExampleRelpClient(listenPort).send("Hello, World again!");

/*
* Stop eventLoop
Expand All @@ -158,15 +153,6 @@ public FrameDelegate get() {
}
System.out.println("server stopped at port <" + listenPort + ">");

/*
* Close the frameDelegate
*/
try {
frameDelegate.close();
}
catch (Exception e) {
throw new RuntimeException(e);
}
executorService.shutdown();
}
}

0 comments on commit ef15554

Please sign in to comment.