Exception immediately after Expunging mailbox Java Email - java

Upon calling the following I code snipit:
Message message_in = null;
inbox instanceof IMAPFolder
IMAPFolder f = (IMAPFolder)inbox;
f.idle();
System.out.println("IDLE done");
message_in = inbox.getMessage(inbox.getMessageCount());
message_in.setFlag(Flags.Flag.DELETED, true);
inbox.expunge();
I receive the error message:
Got 1 new messages
***********************************************************
------------ Message 1 ------------
DONE
A4 OK IDLE completed.
A5 FETCH 13 (ENVELOPE INTERNALDATE RFC822.SIZE)
IDLE done
* 13 FETCH (ENVELOPE ("Wed, 29 Aug 2012 13:25:15 -0500" "Doc Com: Voice msg from Outside caller 5555555555 Unread:2" (("Support" NIL "support" "example.com")) NIL NIL (("Support" NIL "support" "example.com")) NIL NIL "<94BA85B8-FC4D-4193-B386-7FD2C1DE1B1F#example.com>" "<873439BD-8640-47D9-BF88-5FD3521B8173#example.com>") INTERNALDATE "29-Aug-2012 13:25:17 -0500" RFC822.SIZE 967)
A5 OK FETCH completed.
A6 STORE 13 +FLAGS (\Deleted)
* 13 FETCH (FLAGS (\Deleted \Recent))
A6 OK STORE completed.
A7 EXPUNGE
* 13 EXPUNGE
* 12 EXPUNGE
* 11 EXPUNGE
* 10 EXPUNGE
* 9 EXPUNGE
* 8 EXISTS
A7 OK EXPUNGE completed.
javax.mail.MessageRemovedException
at com.sun.mail.imap.IMAPMessage.checkExpunged(IMAPMessage.java:205)
at com.sun.mail.imap.IMAPMessage.loadBODYSTRUCTURE(IMAPMessage.java:1305)
at com.sun.mail.imap.IMAPMessage.getContentType(IMAPMessage.java:450)
at javax.mail.internet.MimeBodyPart.isMimeType(MimeBodyPart.java:1050)
at javax.mail.internet.MimeMessage.isMimeType(MimeMessage.java:986)
at com.example.vmmonitor.main.VMMonitor.getText(VMMonitor.java:211)
at com.example.vmmonitor.main.VMMonitor.access$000(VMMonitor.java:27)
at com.example.vmmonitor.main.VMMonitor$1.messagesAdded(VMMonitor.java:109)
at javax.mail.event.MessageCountEvent.dispatch(MessageCountEvent.java:150)
at javax.mail.EventQueue.run(EventQueue.java:134)
at java.lang.Thread.run(Thread.java:680)
DEBUG IMAP: IMAPProtocol noop
I was able to patch the issues by adding a Thread.sleep() as follows:
What is the issue? Why am I able to flag a message as DELETED but I am not able to expunge the mailbox?
Message message_in = null;
inbox instanceof IMAPFolder
IMAPFolder f = (IMAPFolder)inbox;
f.idle();
System.out.println("IDLE done");
message_in = inbox.getMessage(inbox.getMessageCount());
message_in.setFlag(Flags.Flag.DELETED, true);
Thread.sleep(2000);/*****************bug patch***********/
inbox.expunge();

This multithreaded program is not accessing the inbox resource in a non-thread safe manor. The program is defined in a manor such that inbox.expunge(); and an additional functioning are mutually accessing the mailbox and hence the exception is thrown.

Related

Parallel requests from one client processed in series in RSocket

I expect that all invocations of the server will be processed in parallel, but it is not true.
Here is simple example.
RSocket version: 1.1.0
Server
public class ServerApp {
private static final Logger log = LoggerFactory.getLogger(ServerApp.class);
public static void main(String[] args) throws InterruptedException {
RSocketServer.create(SocketAcceptor.forRequestResponse(payload ->
Mono.fromCallable(() -> {
log.debug("Start of my business logic");
sleepSeconds(5);
return DefaultPayload.create("OK");
})))
.bind(WebsocketServerTransport.create(15000))
.block();
log.debug("Server started");
TimeUnit.MINUTES.sleep(30);
}
private static void sleepSeconds(int sec) {
try {
TimeUnit.SECONDS.sleep(sec);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Client
public class ClientApp {
private static final Logger log = LoggerFactory.getLogger(ClientApp.class);
public static void main(String[] args) throws InterruptedException {
RSocket client = RSocketConnector.create()
.connect(WebsocketClientTransport.create(15000))
.block();
long start1 = System.currentTimeMillis();
client.requestResponse(DefaultPayload.create("Request 1"))
.doOnNext(r -> log.debug("finished within {}ms", System.currentTimeMillis() - start1))
.subscribe();
long start2 = System.currentTimeMillis();
client.requestResponse(DefaultPayload.create("Request 2"))
.doOnNext(r -> log.debug("finished within {}ms", System.currentTimeMillis() - start2))
.subscribe();
TimeUnit.SECONDS.sleep(20);
}
}
In client logs, we can see that both request was sent at the same time, and both responses was received at the same time after 10sec (each request was proceed in 5 seconds).
In server logs, we can see that requests executed sequentially and not in parallel.
Could you please help me to understand this behavior?
Why we have received the first response after 10 seconds and not 5?
How do I create the server correctly if I want all requests to be processed in parallel?
If I replace Mono.fromCallable by Mono.fromFuture(CompletableFuture.supplyAsync(() -> myBusinessLogic(), executorService)), then it will resolve 1.
If I replace Mono.fromCallable by Mono.delay(Duration.ZERO).map(ignore -> myBusinessLogic(), then it will resolve 1. and 2.
If I replace Mono.fromCallable by Mono.create(sink -> sink.success(myBusinessLogic())), then it will not resolve my issues.
Client logs:
2021-07-16 10:39:46,880 DEBUG [reactor-tcp-nio-1] [/] - sending ->
Frame => Stream ID: 0 Type: SETUP Flags: 0b0 Length: 56
Data:
2021-07-16 10:39:46,952 DEBUG [main] [/] - sending ->
Frame => Stream ID: 1 Type: REQUEST_RESPONSE Flags: 0b0 Length: 15
Data:
+-------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------+-------------------------------------------------+----------------+
|00000000| 52 65 71 75 65 73 74 20 31 |Request 1 |
+--------+-------------------------------------------------+----------------+
2021-07-16 10:39:46,957 DEBUG [main] [/] - sending ->
Frame => Stream ID: 3 Type: REQUEST_RESPONSE Flags: 0b0 Length: 15
Data:
+-------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------+-------------------------------------------------+----------------+
|00000000| 52 65 71 75 65 73 74 20 32 |Request 2 |
+--------+-------------------------------------------------+----------------+
2021-07-16 10:39:57,043 DEBUG [reactor-tcp-nio-1] [/] - receiving ->
Frame => Stream ID: 1 Type: NEXT_COMPLETE Flags: 0b1100000 Length: 8
Data:
+-------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------+-------------------------------------------------+----------------+
|00000000| 4f 4b |OK |
+--------+-------------------------------------------------+----------------+
2021-07-16 10:39:57,046 DEBUG [reactor-tcp-nio-1] [/] - finished within 10120ms
2021-07-16 10:39:57,046 DEBUG [reactor-tcp-nio-1] [/] - receiving ->
Frame => Stream ID: 3 Type: NEXT_COMPLETE Flags: 0b1100000 Length: 8
Data:
+-------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------+-------------------------------------------------+----------------+
|00000000| 4f 4b |OK |
+--------+-------------------------------------------------+----------------+
2021-07-16 10:39:57,046 DEBUG [reactor-tcp-nio-1] [/] - finished within 10094ms
Server Logs:
2021-07-16 10:39:46,965 DEBUG [reactor-http-nio-2] [/] - receiving ->
Frame => Stream ID: 0 Type: SETUP Flags: 0b0 Length: 56
Data:
2021-07-16 10:39:47,021 DEBUG [reactor-http-nio-2] [/] - receiving ->
Frame => Stream ID: 1 Type: REQUEST_RESPONSE Flags: 0b0 Length: 15
Data:
+-------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------+-------------------------------------------------+----------------+
|00000000| 52 65 71 75 65 73 74 20 31 |Request 1 |
+--------+-------------------------------------------------+----------------+
2021-07-16 10:39:47,027 DEBUG [reactor-http-nio-2] [/] - Start of my business logic
2021-07-16 10:39:52,037 DEBUG [reactor-http-nio-2] [/] - sending ->
Frame => Stream ID: 1 Type: NEXT_COMPLETE Flags: 0b1100000 Length: 8
Data:
+-------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------+-------------------------------------------------+----------------+
|00000000| 4f 4b |OK |
+--------+-------------------------------------------------+----------------+
2021-07-16 10:39:52,038 DEBUG [reactor-http-nio-2] [/] - receiving ->
Frame => Stream ID: 3 Type: REQUEST_RESPONSE Flags: 0b0 Length: 15
Data:
+-------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------+-------------------------------------------------+----------------+
|00000000| 52 65 71 75 65 73 74 20 32 |Request 2 |
+--------+-------------------------------------------------+----------------+
2021-07-16 10:39:52,038 DEBUG [reactor-http-nio-2] [/] - Start of my business logic
2021-07-16 10:39:57,039 DEBUG [reactor-http-nio-2] [/] - sending ->
Frame => Stream ID: 3 Type: NEXT_COMPLETE Flags: 0b1100000 Length: 8
Data:
+-------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------+-------------------------------------------------+----------------+
|00000000| 4f 4b |OK |
+--------+-------------------------------------------------+----------------+
You shouldn't mix asynchronous code like Reactive Mono operations with blocking code like
private static void sleepSeconds(int sec) {
try {
TimeUnit.SECONDS.sleep(sec);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
I suspect the central issue here is that a framework like rsocket-java doesn't want to run everything on new threads, at the cost of excessive context switching. So generally relies on you run long running CPU or IO operations appropriately.
You should look at the various async delay operations instead https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Mono.html#delayElement-java.time.Duration-
If your delay is meant to simulate a long running operation, then you should look at subscribing on a different scheduler like https://projectreactor.io/docs/core/release/api/reactor/core/scheduler/Schedulers.html#boundedElastic--

Trying to understand threads in java in this case

Hi I'm trying to understand my code, I have user synchronized key word in a method, to make that only one thread use it.
The main class:
public class Principal {
public static void main(String[] args) {
Messenger messenger = new Messenger();
Hilo t1 = new Hilo(messenger);
Hilo t2 = new Hilo(messenger);
t1.start();
t2.start();
}
}
The messenger class:
public class Messenger {
private String msg = "hello";
synchronized public void sendMessage() {
System.out.println(msg + " from " + Thread.currentThread().getName());
}
}
And the thred class:
public class Hilo extends Thread {
private Messenger messenger;
public Hilo(Messenger messenger) {
this.messenger = messenger;
}
#Override
public void run() {
while (true) {
messenger.sendMessage();
}
}
}
I had this output:
hello from Thread-1
hello from Thread-1
hello from Thread-1
hello from Thread-1
hello from Thread-1
hello from Thread-0
hello from Thread-0
hello from Thread-1
hello from Thread-1
hello from Thread-1
hello from Thread-1
hello from Thread-0
hello from Thread-0
hello from Thread-0
hello from Thread-0
hello from Thread-0
hello from Thread-0
hello from Thread-0
...
But I was expected this:
hello from Thread-1
hello from Thread-0
hello from Thread-1
hello from Thread-0
hello from Thread-1
hello from Thread-0
hello from Thread-1
hello from Thread-0
hello from Thread-1
hello from Thread-0
hello from Thread-1
hello from Thread-0
hello from Thread-1
hello from Thread-0
...
I've been thinking but I can't understand the failure.
Please add your opinion .
Thanks in advance.
Your resulting output got about 18 cycles done with about 3 context switches. Your "expected" output got 14 cycles done with 14 context switches. It seems the behavior you got is much better than you expected.
The question is why you would expect such inefficient behavior. Alternation is about the worst possible performance given that more context switches are needed, more caches are blown out, and so on. No sensible implementation would do that if it could find any way to avoid it.
Generally speaking, you want to keep a thread running as long as possible because context switches have cost. A good implementation balances performance with other priorities, sure, but it doesn't give up performance for no good reason.
Always use timestamps to verify order of happening
Actually, System.out.println makes poor mechanism for testing concurrency. The calls do not actually get output in the order they were called. In other words, never rely on the order of appearance in System.out as representing actual order of happening.
You can see this behavior by including calls to Instant.now() or System.nanoTime. I suggest always adding such calls in almost any kind of testing/debugging where order matters. If you look carefully at the microseconds, you will see later items appearing on your console before earlier items.
Even better suggestion: Put your outputs into a thread-safe collection. Dump to console at end of your test.
Executor service
In modern Java, we rarely need to address the Thread class directly.
Instead, use an executor service. The service is backed by a pool of one or more threads. The service handles creating and recreating threads as needed, depending on its promised behavior.
Write your task as a Runnable, an object with a run method, or a Callable with an call method.
Example code
Here is my revised version of your code.
Our singleton Messenger class. One instance to be shared across two threads.
Tip: Call Thread#getId rather than Thread#getName to identify a thread. Virtual threads in the future Project Loom may lack names by default.
package work.basil.example.order;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Messenger
{
final private String msg = "hello";
final List < String > outputs = new ArrayList <>( 100 ); // Need not be thread-safe for this demo, as we only touch it from within our `synchronized` method `sendMessage`.
synchronized public void sendMessage ( )
{
String output = this.msg + " from thread id # " + Thread.currentThread().getId() + " at " + Instant.now();
this.outputs.add( output );
}
}
Our Runnable task class. It keeps hold of a Messenger object to be used on each run execution.
Tip: Rather than running endlessly as seen in your code with while ( true ), write while ( ! Thread.interrupted() ) to run until the interrupted flag has been thrown for that thread. The ExecutorService#shutdownNow method will likely set that flag for us, enabling our threads to shut themselves down.
package work.basil.example.order;
import java.util.Objects;
public class Hilo implements Runnable
{
// Member fields
final private String id;
final private Messenger messenger;
// Constructors
public Hilo ( final String id , final Messenger messenger )
{
this.id = id;
this.messenger = Objects.requireNonNull( messenger );
}
#Override
public void run ( )
{
while ( ! Thread.interrupted() )
{
this.messenger.sendMessage();
}
}
}
An app class to exercise run our demo.
package work.basil.example.order;
import java.time.Instant;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class App
{
public static void main ( String[] args )
{
App app = new App();
app.demo();
}
private void demo ( )
{
Messenger messenger = new Messenger();
ExecutorService executorService = Executors.newFixedThreadPool( 2 );
System.out.println( "INFO - Submitting tasks. " + Instant.now() );
executorService.submit( new Hilo( "Alice" , messenger ) );
executorService.submit( new Hilo( "Bob" , messenger ) );
executorService.shutdown();
try
{
// Wait a while for existing tasks to terminate
if ( ! executorService.awaitTermination( 15 , TimeUnit.MILLISECONDS ) )
{
executorService.shutdownNow(); // Set "interrupted" flag on threads currently executing tasks.
// Wait a while for tasks to respond to interrupted flag being set.
if ( ! executorService.awaitTermination( 1 , TimeUnit.SECONDS ) )
System.err.println( "WARN - executorService did not terminate." );
}
}
catch ( InterruptedException e ) { e.printStackTrace(); }
System.out.println( "INFO - Done with demo. Results array appears next. " + Instant.now() );
int nthOutput = 0;
for ( String output : messenger.outputs )
{
nthOutput++;
System.out.println( "output " + nthOutput + " = " + output );
}
}
}
When run on my Mac mini Intel with six real cores and no Hyper-Threading using early-access Java 17, I see dozens of outputs at a time per thread. Notice in this sample below how the first 3 are thread ID 14, followed by # 4-71 being all thread ID 15.
As the Answer by David Schwartz explains, letting a thread run a while is usually more efficient.
INFO - Submitting tasks. 2021-03-23T02:46:58.490916Z
INFO - Done with demo. Results array appears next. 2021-03-23T02:46:58.527018Z
output 1 = hello from thread id # 14 at 2021-03-23T02:46:58.509450Z
output 2 = hello from thread id # 14 at 2021-03-23T02:46:58.522884Z
output 3 = hello from thread id # 14 at 2021-03-23T02:46:58.522923Z
output 4 = hello from thread id # 15 at 2021-03-23T02:46:58.522956Z
output 5 = hello from thread id # 15 at 2021-03-23T02:46:58.523011Z
output 6 = hello from thread id # 15 at 2021-03-23T02:46:58.523041Z
output 7 = hello from thread id # 15 at 2021-03-23T02:46:58.523077Z
output 8 = hello from thread id # 15 at 2021-03-23T02:46:58.523106Z
output 9 = hello from thread id # 15 at 2021-03-23T02:46:58.523134Z
output 10 = hello from thread id # 15 at 2021-03-23T02:46:58.523165Z
output 11 = hello from thread id # 15 at 2021-03-23T02:46:58.523197Z
output 12 = hello from thread id # 15 at 2021-03-23T02:46:58.523227Z
output 13 = hello from thread id # 15 at 2021-03-23T02:46:58.523254Z
output 14 = hello from thread id # 15 at 2021-03-23T02:46:58.523282Z
output 15 = hello from thread id # 15 at 2021-03-23T02:46:58.523312Z
output 16 = hello from thread id # 15 at 2021-03-23T02:46:58.523343Z
output 17 = hello from thread id # 15 at 2021-03-23T02:46:58.523381Z
output 18 = hello from thread id # 15 at 2021-03-23T02:46:58.523410Z
output 19 = hello from thread id # 15 at 2021-03-23T02:46:58.523436Z
output 20 = hello from thread id # 15 at 2021-03-23T02:46:58.523466Z
output 21 = hello from thread id # 15 at 2021-03-23T02:46:58.523495Z
output 22 = hello from thread id # 15 at 2021-03-23T02:46:58.523522Z
output 23 = hello from thread id # 15 at 2021-03-23T02:46:58.523550Z
output 24 = hello from thread id # 15 at 2021-03-23T02:46:58.523583Z
output 25 = hello from thread id # 15 at 2021-03-23T02:46:58.523612Z
output 26 = hello from thread id # 15 at 2021-03-23T02:46:58.523640Z
output 27 = hello from thread id # 15 at 2021-03-23T02:46:58.523668Z
output 28 = hello from thread id # 15 at 2021-03-23T02:46:58.523696Z
output 29 = hello from thread id # 15 at 2021-03-23T02:46:58.523760Z
output 30 = hello from thread id # 15 at 2021-03-23T02:46:58.523798Z
output 31 = hello from thread id # 15 at 2021-03-23T02:46:58.523828Z
output 32 = hello from thread id # 15 at 2021-03-23T02:46:58.523858Z
output 33 = hello from thread id # 15 at 2021-03-23T02:46:58.523883Z
output 34 = hello from thread id # 15 at 2021-03-23T02:46:58.523915Z
output 35 = hello from thread id # 15 at 2021-03-23T02:46:58.523943Z
output 36 = hello from thread id # 15 at 2021-03-23T02:46:58.523971Z
output 37 = hello from thread id # 15 at 2021-03-23T02:46:58.523996Z
output 38 = hello from thread id # 15 at 2021-03-23T02:46:58.524020Z
output 39 = hello from thread id # 15 at 2021-03-23T02:46:58.524049Z
output 40 = hello from thread id # 15 at 2021-03-23T02:46:58.524077Z
output 41 = hello from thread id # 15 at 2021-03-23T02:46:58.524102Z
output 42 = hello from thread id # 15 at 2021-03-23T02:46:58.524128Z
output 43 = hello from thread id # 15 at 2021-03-23T02:46:58.524156Z
output 44 = hello from thread id # 15 at 2021-03-23T02:46:58.524181Z
output 45 = hello from thread id # 15 at 2021-03-23T02:46:58.524212Z
output 46 = hello from thread id # 15 at 2021-03-23T02:46:58.524239Z
output 47 = hello from thread id # 15 at 2021-03-23T02:46:58.524262Z
output 48 = hello from thread id # 15 at 2021-03-23T02:46:58.524284Z
output 49 = hello from thread id # 15 at 2021-03-23T02:46:58.524308Z
output 50 = hello from thread id # 15 at 2021-03-23T02:46:58.524336Z
output 51 = hello from thread id # 15 at 2021-03-23T02:46:58.524359Z
output 52 = hello from thread id # 15 at 2021-03-23T02:46:58.524381Z
output 53 = hello from thread id # 15 at 2021-03-23T02:46:58.524405Z
output 54 = hello from thread id # 15 at 2021-03-23T02:46:58.524428Z
output 55 = hello from thread id # 15 at 2021-03-23T02:46:58.524454Z
output 56 = hello from thread id # 15 at 2021-03-23T02:46:58.524477Z
output 57 = hello from thread id # 15 at 2021-03-23T02:46:58.524499Z
output 58 = hello from thread id # 15 at 2021-03-23T02:46:58.524521Z
output 59 = hello from thread id # 15 at 2021-03-23T02:46:58.524544Z
output 60 = hello from thread id # 15 at 2021-03-23T02:46:58.524570Z
output 61 = hello from thread id # 15 at 2021-03-23T02:46:58.524591Z
output 62 = hello from thread id # 15 at 2021-03-23T02:46:58.524613Z
output 63 = hello from thread id # 15 at 2021-03-23T02:46:58.524634Z
output 64 = hello from thread id # 15 at 2021-03-23T02:46:58.524659Z
output 65 = hello from thread id # 15 at 2021-03-23T02:46:58.524685Z
output 66 = hello from thread id # 15 at 2021-03-23T02:46:58.524710Z
output 67 = hello from thread id # 15 at 2021-03-23T02:46:58.524731Z
output 68 = hello from thread id # 15 at 2021-03-23T02:46:58.524752Z
output 69 = hello from thread id # 15 at 2021-03-23T02:46:58.524780Z
output 70 = hello from thread id # 15 at 2021-03-23T02:46:58.524801Z
output 71 = hello from thread id # 15 at 2021-03-23T02:46:58.524826Z
output 72 = hello from thread id # 14 at 2021-03-23T02:46:58.524852Z
output 73 = hello from thread id # 14 at 2021-03-23T02:46:58.524902Z
output 74 = hello from thread id # 14 at 2021-03-23T02:46:58.524929Z
output 75 = hello from thread id # 14 at 2021-03-23T02:46:58.524954Z
output 76 = hello from thread id # 14 at 2021-03-23T02:46:58.524975Z
output 77 = hello from thread id # 14 at 2021-03-23T02:46:58.524998Z
output 78 = hello from thread id # 14 at 2021-03-23T02:46:58.525021Z
output 79 = hello from thread id # 14 at 2021-03-23T02:46:58.525042Z
output 80 = hello from thread id # 14 at 2021-03-23T02:46:58.525075Z
output 81 = hello from thread id # 14 at 2021-03-23T02:46:58.525095Z
output 82 = hello from thread id # 14 at 2021-03-23T02:46:58.525115Z
output 83 = hello from thread id # 14 at 2021-03-23T02:46:58.525138Z
output 84 = hello from thread id # 14 at 2021-03-23T02:46:58.525159Z
output 85 = hello from thread id # 14 at 2021-03-23T02:46:58.525194Z
output 86 = hello from thread id # 14 at 2021-03-23T02:46:58.525215Z
output 87 = hello from thread id # 14 at 2021-03-23T02:46:58.525241Z
output 88 = hello from thread id # 14 at 2021-03-23T02:46:58.525277Z
output 89 = hello from thread id # 14 at 2021-03-23T02:46:58.525298Z
output 90 = hello from thread id # 14 at 2021-03-23T02:46:58.525319Z
output 91 = hello from thread id # 14 at 2021-03-23T02:46:58.525339Z
output 92 = hello from thread id # 14 at 2021-03-23T02:46:58.525359Z
output 93 = hello from thread id # 14 at 2021-03-23T02:46:58.525381Z
output 94 = hello from thread id # 14 at 2021-03-23T02:46:58.525401Z
output 95 = hello from thread id # 14 at 2021-03-23T02:46:58.525422Z
output 96 = hello from thread id # 14 at 2021-03-23T02:46:58.525452Z
output 97 = hello from thread id # 14 at 2021-03-23T02:46:58.525474Z
output 98 = hello from thread id # 14 at 2021-03-23T02:46:58.525496Z
output 99 = hello from thread id # 14 at 2021-03-23T02:46:58.525515Z
output 100 = hello from thread id # 14 at 2021-03-23T02:46:58.525533Z
output 101 = hello from thread id # 14 at 2021-03-23T02:46:58.525555Z
output 102 = hello from thread id # 14 at 2021-03-23T02:46:58.525581Z
output 103 = hello from thread id # 14 at 2021-03-23T02:46:58.525603Z
output 104 = hello from thread id # 14 at 2021-03-23T02:46:58.525625Z
output 105 = hello from thread id # 14 at 2021-03-23T02:46:58.525645Z
output 106 = hello from thread id # 14 at 2021-03-23T02:46:58.525664Z
output 107 = hello from thread id # 14 at 2021-03-23T02:46:58.525686Z
output 108 = hello from thread id # 14 at 2021-03-23T02:46:58.525705Z
output 109 = hello from thread id # 14 at 2021-03-23T02:46:58.525723Z
output 110 = hello from thread id # 14 at 2021-03-23T02:46:58.525741Z
output 111 = hello from thread id # 14 at 2021-03-23T02:46:58.525758Z
output 112 = hello from thread id # 14 at 2021-03-23T02:46:58.525783Z
output 113 = hello from thread id # 14 at 2021-03-23T02:46:58.525801Z
output 114 = hello from thread id # 14 at 2021-03-23T02:46:58.525818Z
output 115 = hello from thread id # 14 at 2021-03-23T02:46:58.525837Z
output 116 = hello from thread id # 14 at 2021-03-23T02:46:58.525855Z
output 117 = hello from thread id # 14 at 2021-03-23T02:46:58.525875Z
output 118 = hello from thread id # 14 at 2021-03-23T02:46:58.525897Z
output 119 = hello from thread id # 14 at 2021-03-23T02:46:58.525913Z
output 120 = hello from thread id # 15 at 2021-03-23T02:46:58.525931Z
output 121 = hello from thread id # 15 at 2021-03-23T02:46:58.525965Z
output 122 = hello from thread id # 15 at 2021-03-23T02:46:58.526002Z
output 123 = hello from thread id # 15 at 2021-03-23T02:46:58.526023Z
output 124 = hello from thread id # 15 at 2021-03-23T02:46:58.526050Z
output 125 = hello from thread id # 15 at 2021-03-23T02:46:58.526075Z
output 126 = hello from thread id # 15 at 2021-03-23T02:46:58.526095Z
output 127 = hello from thread id # 15 at 2021-03-23T02:46:58.526135Z
output 128 = hello from thread id # 15 at 2021-03-23T02:46:58.526169Z
output 129 = hello from thread id # 15 at 2021-03-23T02:46:58.526233Z
output 130 = hello from thread id # 15 at 2021-03-23T02:46:58.526260Z
output 131 = hello from thread id # 15 at 2021-03-23T02:46:58.526279Z
output 132 = hello from thread id # 15 at 2021-03-23T02:46:58.526297Z
output 133 = hello from thread id # 15 at 2021-03-23T02:46:58.526315Z
output 134 = hello from thread id # 15 at 2021-03-23T02:46:58.526335Z
output 135 = hello from thread id # 15 at 2021-03-23T02:46:58.526352Z
output 136 = hello from thread id # 15 at 2021-03-23T02:46:58.526370Z
output 137 = hello from thread id # 15 at 2021-03-23T02:46:58.526389Z
output 138 = hello from thread id # 15 at 2021-03-23T02:46:58.526405Z
output 139 = hello from thread id # 15 at 2021-03-23T02:46:58.526424Z
output 140 = hello from thread id # 15 at 2021-03-23T02:46:58.526441Z
output 141 = hello from thread id # 14 at 2021-03-23T02:46:58.526465Z
output 142 = hello from thread id # 14 at 2021-03-23T02:46:58.526500Z
output 143 = hello from thread id # 14 at 2021-03-23T02:46:58.526524Z
output 144 = hello from thread id # 14 at 2021-03-23T02:46:58.526552Z
output 145 = hello from thread id # 14 at 2021-03-23T02:46:58.526570Z
output 146 = hello from thread id # 14 at 2021-03-23T02:46:58.526588Z
output 147 = hello from thread id # 14 at 2021-03-23T02:46:58.526605Z
output 148 = hello from thread id # 14 at 2021-03-23T02:46:58.526621Z
output 149 = hello from thread id # 14 at 2021-03-23T02:46:58.526642Z
output 150 = hello from thread id # 14 at 2021-03-23T02:46:58.526658Z
output 151 = hello from thread id # 14 at 2021-03-23T02:46:58.526674Z
output 152 = hello from thread id # 14 at 2021-03-23T02:46:58.526696Z
output 153 = hello from thread id # 15 at 2021-03-23T02:46:58.526715Z
Your expectation seems to be that the thread scheduler was going to give equal, round-robin, time slices of liveliness for each thread.
The Java language, however, offers no guarantees with respects to thread scheduling, leaving that responsibility instead to the underlying operating system. If the threads in your application aren't performing time-sensitive work, you can sort of file this away as an implementation detail and just assume the scheduler is going try to give some fair distribution of running time for each thread (assuming of course the thread logic itself doesn't starve the other runnable threads).
Note also that you can assign a priority to threads, but again, this doesn't offer any guarantee of execution order and is only declarative of your intent since the scheduling is ultimately left up to the underlying OS.
Java thread scheduling algorithm is the one who decide which thread should be running at any given point of time. And this algorithm is only concerned about threads in the Runnable state.
Now comes the role of Thread priority. Java threads can have an integer value from 1 to 10, as its priority. You can set the priority to a thread by threadName.setPriority(value).
If not specified, thread will take the priority value 5 by default.
So, in your case, both the threads have same priority value 5.
As to java scheduling rule, at any given point of time, the highest priority thread is running. But this rule is not guaranteed due to few reasons (ex:JVM try to avoid starvation).
Now here since you have 2 threads of same priority level, Java thread scheduler randomly select one thread (let's say t1) and execute. The other thread (t2) will get the chance to be executed when one of the following things happen,
t1 completes whatever inside t1's run method and compete again to execute. But you can't guarantee next chance will be t2's. (This is what's happening in your case)
you call t1.yield() method. t1 give up the processor and give the chance to any other same priority thread. well, t2. (But can't always guarantee)
Preempted by a higher priority thread.
The system is using Time Slicing Rule and that specific time expires. (Again, can't guarantee t2 will be next).
If you really want to get the desired 0,1,0,1 "fair" output here, you can write a logic to the synchronized method in the Messenger class. Something like this;
class Messenger {
private String msg = "hello";
private boolean state; //define a state variable
synchronized public void sendMessage() {
while(state == false){
if(!Thread.currentThread().getName().equals("Thread-0")){ //if not thread-0, then go to wait queue
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
else{//if thread-0 , print and change state variable value.
System.out.println(msg + " from " + Thread.currentThread().getName());
state = true;
notifyAll();
}
}
if(!Thread.currentThread().getName().equals("Thread-1")){//if not thread-1, then go to wait queue
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
else{//if thread-1 , print and change state variable value.
System.out.println(msg + " from " + Thread.currentThread().getName());
state = false;
notifyAll();
}
}
}

Axis exception: o.a.axis2.transport.http.HTTPSender.sendViaPost(196) - Unable to sendViaPost - Connection refused

I have a server that is executing a Webservice call to an external server.
This call has to occur over SSL and using a proxy:
My truststore is well configured:
trustStore is: /opt/configuration/keystore/truststore.jks
trustStore type is : jks
trustStore provider is :
init truststore
adding as trusted cert:
Also my handshake is done correctly:
https-jsse-nio-8443-exec-6, READ: TLSv1.2 Handshake, length = 40
Padded plaintext after DECRYPTION: len = 16
0000: 14 00 00 0C 78 49 E5 E1 29 04 A5 1D FC 4F E6 E2 ....xI..)....O..
*** Finished
verify_data: { 120, 73, 229, 225, 41, 4, 165, 29, 252, 79, 230, 226 }
***
[read] MD5 and SHA1 hashes: len = 16
0000: 14 00 00 0C 78 49 E5 E1 29 04 A5 1D FC 4F E6 E2 ....xI..)....O..
https-jsse-nio-8443-exec-6, WRITE: TLSv1.2 Change Cipher Spec, length = 1
[Raw write]: length = 6
0000: 14 03 03 00 01 01 ......
*** Finished
I have a ProxySelector that selects a proxy to use:
#Override
public List<Proxy> select(URI uri) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("select for URL : " + uri);
}
if (uri == null) {
throw new IllegalArgumentException("URI cannot be null.");
}
// Get protocol and management configuration for HTTP or HTTPS.
String protocol = uri.getScheme();
if (StringUtils.equalsIgnoreCase("http", protocol)
|| StringUtils.equalsIgnoreCase("https", protocol)
|| StringUtils.equalsIgnoreCase("socket", protocol)) {
LOGGER.debug("Retrieving proxy list...");
List<Proxy> proxyList = new ArrayList<>();
for (InnerProxy p : proxies.values()) {
proxyList.add(p.toProxy());
}
LOGGER.debug(proxyList.size() + " configured proxies");
// Return configured Proxy
return proxyList;
}
/*
* For others protocols (could be SOCKS or FTP etc.) return the default
* selector.
*/
if (defaultSelector != null) {
return defaultSelector.select(uri);
} else {
List<Proxy> proxyList = new ArrayList<>();
proxyList.add(Proxy.NO_PROXY);
return proxyList;
}
}
But when calling a method on a webmethod generated by JAX-WS RI:
/**
*
* #param base64ObjectToValidate
* #param xmlMetadata
* #param xmlReferencedStandard
* #return
* returns java.lang.String
* #throws SOAPException_Exception
*/
#WebMethod
#WebResult(name = "validationResult", targetNamespace = "")
#RequestWrapper(localName = "validateObject", targetNamespace = "http://ws.validator.sch.gazelle.ihe.net/", className = "net.ihe.gazelle.schematron.ValidateObject")
#ResponseWrapper(localName = "validateObjectResponse", targetNamespace = "http://ws.validator.sch.gazelle.ihe.net/", className = "net.ihe.gazelle.schematron.ValidateObjectResponse")
public String validateObject(
#WebParam(name = "base64ObjectToValidate", targetNamespace = "")
String base64ObjectToValidate,
#WebParam(name = "xmlReferencedStandard", targetNamespace = "")
String xmlReferencedStandard,
#WebParam(name = "xmlMetadata", targetNamespace = "")
String xmlMetadata)
throws SOAPException_Exception
;
I get 8 query select requests (where I would only expect 1):
15:55:30.228+02:00 [https-jsse-nio-8443-exec-6] DEBUG e.epsos.util.net.CustomProxySelector.select(43) - select for URL : https://gazelle.ehdsi.ihe-europe.net/SchematronValidator-ejb/GazelleObjectValidatorService/GazelleObjectValidator?wsdl
15:55:30.495+02:00 [https-jsse-nio-8443-exec-6] DEBUG e.epsos.util.net.CustomProxySelector.select(43) - select for URL : https://gazelle.ehdsi.ihe-europe.net/SchematronValidator-ejb/GazelleObjectValidatorService/GazelleObjectValidator?wsdl
15:55:30.637+02:00 [https-jsse-nio-8443-exec-6] DEBUG e.epsos.util.net.CustomProxySelector.select(43) - select for URL : https://gazelle.ehdsi.ihe-europe.net/SchematronValidator-ejb/GazelleObjectValidatorService/GazelleObjectValidator?wsdl
15:55:30.667+02:00 [https-jsse-nio-8443-exec-6] DEBUG e.epsos.util.net.CustomProxySelector.select(43) - select for URL : https://gazelle.ehdsi.ihe-europe.net/SchematronValidator-ejb/GazelleObjectValidatorService/GazelleObjectValidator?wsdl
15:55:31.130+02:00 [https-jsse-nio-8443-exec-6] DEBUG e.epsos.util.net.CustomProxySelector.select(43) - select for URL : socket://gazelle.ehdsi.ihe-europe.net:443
15:55:31.134+02:00 [https-jsse-nio-8443-exec-6] DEBUG e.epsos.util.net.CustomProxySelector.select(43) - select for URL : socket://gazelle.ehdsi.ihe-europe.net:443
15:55:31.137+02:00 [https-jsse-nio-8443-exec-6] DEBUG e.epsos.util.net.CustomProxySelector.select(43) - select for URL : socket://gazelle.ehdsi.ihe-europe.net:443
15:55:31.140+02:00 [https-jsse-nio-8443-exec-6] DEBUG e.epsos.util.net.CustomProxySelector.select(43) - select for URL : socket://gazelle.ehdsi.ihe-europe.net:443
The Custom Proxy selector is called 4 times for the real URL and 4 times for the socket.
And in the logs I got following exception caused by a HTTP request initiated by Axis (I'm using Axis version 1.6.2):
15:55:31.137+02:00 [https-jsse-nio-8443-exec-6] DEBUG e.epsos.util.net.CustomProxySelector.select(43) - select for URL : socket://gazelle.ehdsi.ihe-europe.net:443
15:55:31.139+02:00 [https-jsse-nio-8443-exec-6] DEBUG o.a.c.httpclient.HttpMethodDirector.executeWithRetry(404) - Closing the connection.
15:55:31.139+02:00 [https-jsse-nio-8443-exec-6] INFO o.a.c.httpclient.HttpMethodDirector.executeWithRetry(439) - I/O exception (java.net.ConnectException) caught when processing request: Connection refused (Connection refused)
15:55:31.139+02:00 [https-jsse-nio-8443-exec-6] DEBUG o.a.c.httpclient.HttpMethodDirector.executeWithRetry(443) - Connection refused (Connection refused)
java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:140)
at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:130)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.execute(AxisInvocationController.java:578)
at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.doInvoke(AxisInvocationController.java:127)
at org.apache.axis2.jaxws.core.controller.impl.InvocationControllerImpl.invoke(InvocationControllerImpl.java:93)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:373)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invoke(JAXWSProxyHandler.java:171)
at com.sun.proxy.$Proxy137.validateObject(Unknown Source)
I have no idea why Axis executes these calls and why I have a java.net.ConnectException: Connection refused (Connection refused) exception...
Looks like he doesn't use the configured proxy...
Hope anyone could help me out...
I found following lines in my logging:
16:35:35.676+02:00 [https-jsse-nio-8443-exec-5] DEBUG o.a.c.httpclient.HttpConnection.open(692) - Open connection to gazelle.ehdsi.ihe-europe.net:443
16:35:35.677+02:00 [https-jsse-nio-8443-exec-5] DEBUG e.epsos.util.net.CustomProxySelector.select(43) - select for URL : socket://gazelle.ehdsi.ihe-europe.net:443
16:35:35.677+02:00 [https-jsse-nio-8443-exec-5] DEBUG e.epsos.util.net.CustomProxySelector.select(52) - protocol is : socket
16:35:35.677+02:00 [https-jsse-nio-8443-exec-5] DEBUG e.epsos.util.net.CustomProxySelector.select(56) - Retrieving proxy list...
16:35:35.677+02:00 [https-jsse-nio-8443-exec-5] DEBUG e.epsos.util.net.CustomProxySelector.select(62) - 1 configured proxies
16:35:35.680+02:00 [https-jsse-nio-8443-exec-5] DEBUG o.a.c.httpclient.HttpMethodDirector.executeWithRetry(404) - Closing the connection.
16:35:35.680+02:00 [https-jsse-nio-8443-exec-5] DEBUG o.a.c.httpclient.HttpMethodDirector.executeWithRetry(434) - Method retry handler returned false. Automatic recovery will not be attempted
16:35:35.680+02:00 [https-jsse-nio-8443-exec-5] DEBUG o.a.c.httpclient.HttpConnection.releaseConnection(1178) - Releasing connection back to connection manager.
16:35:35.680+02:00 [https-jsse-nio-8443-exec-5] DEBUG o.a.c.h.MultiThreadedHttpConnectionManager.freeConnection(979) - Freeing connection, hostConfig=HostConfiguration[host=https://gazelle.ehdsi.ihe-europe.net]
16:35:35.680+02:00 [https-jsse-nio-8443-exec-5] DEBUG o.a.c.h.util.IdleConnectionHandler.add(76) - Adding connection at: 1503930935680
16:35:35.681+02:00 [https-jsse-nio-8443-exec-5] DEBUG o.a.c.h.MultiThreadedHttpConnectionManager.notifyWaitingThread(961) - Notifying no-one, there are no waiting threads
16:35:35.681+02:00 [https-jsse-nio-8443-exec-5] INFO o.a.axis2.transport.http.HTTPSender.sendViaPost(196) - Unable to sendViaPost to url[https://gazelle.ehdsi.ihe-europe.net/SchematronValidator-ejb/GazelleObjectValidatorService/GazelleObjectValidator]
java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at
java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at
java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at
java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
I think the reason why it doesn't work is explained in this bugreport. It's 11 years old and still marked as unresolved. The comment clearly says that there are no plans to implement that but there might be a workaround:
However, Axis1.x and 2.x can both switch to use the jakarta-commons
httpclient library. This is what you should be using if you can,
because it understads HTTP properly. If you could get proxy support in
there, either axis build could pick it up.
As far as I remember, the commons HTTP client supports ProxySelector.

Netty 4.0: Spawning off, maintaining and communicating with many clients/peers (TCP)

I have an unknown number of peers that I will need to make TCP connections to. I'm running into a few problems and not certain whether my overall approach is correct. My current set up on the client side consists of a Peer Manager that shares its EventLoopGroup and creates clients as needed:
public class PeerManagement
{
public PeerManagement()
{
// this group is shared across all clients
_eventLoopGroup = new NioEventLoopGroup();
_peers = new ConcurrentHashMap<>();
}
public void send(String s, String host)
{
// ensure that the peer exists
setPeer(host);
// look up the peer
Peer requestedPeer = _peers.get(host);
// send the request directly to the peer
requestedPeer.send(s);
}
private synchronized void setPeer(String host)
{
if (!_peers.containsKey(host))
{
// create the Peer using the EventLoopGroup & connect
Peer peer = new Peer();
peer.connect(_eventLoopGroup, host);
// add the peer to the Peer list
_peers.put(host, peer);
}
}
}
The Peer class:
public class Peer
{
private static final int PORT = 6010;
private Bootstrap _bootstrap;
private ChannelFuture _channelFuture;
public boolean connect(EventLoopGroup eventLoopGroup, String host)
{
_bootstrap = new Bootstrap();
_bootstrap.group(eventLoopGroup)
.channel(NioSocketChannel.class)
.option(ChannelOption.SO_KEEPALIVE, true)
.handler(new ChannelInitializer<SocketChannel>()
{
#Override
public void initChannel(SocketChannel socketChannel) throws Exception
{
socketChannel.pipeline().addLast(new LengthFieldBasedFrameDecoder( 1024,0,4,0,4));
socketChannel.pipeline().addLast(new LengthFieldPrepender(4));
socketChannel.pipeline().addLast("customHandler", new CustomPeerHandler());
}
} );
// hold this for communicating with client
_channelFuture = _bootstrap.connect(host, PORT);
return _channelFuture.syncUninterruptibly().isSuccess();
}
public boolean send(String s)
{
if (_channelFuture.channel().isWritable())
{
// not the best method but String will be replaced by byte[]
ByteBuf buffer = _channelFuture.channel().alloc().buffer();
buffer.writeBytes(s.getBytes());
// NEVER returns true but the message is sent
return _channelFuture.channel().writeAndFlush(buffer).isSuccess();
}
return false;
}
}
If I send the following string "this is a test" then writeAndFlush.isSuccess() is always false but sends the message and then I get the following on the server side:
+-------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------+-------------------------------------------------+----------------+
|00000000| ff 00 00 00 00 00 00 00 01 7f |.......... |
+--------+-------------------------------------------------+----------------+
+-------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------+-------------------------------------------------+----------------+
|00000000| 00 00 00 0e 74 68 69 73 20 69 73 20 61 20 74 65 |....this is a te|
|00000010| 73 74 |st |
+--------+-------------------------------------------------+----------------+
io.netty.handler.codec.TooLongFrameException: Adjusted frame length exceeds 1024: 4278190084 - discarded
+-------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------+-------------------------------------------------+----------------+
|00000000| ff 00 00 00 00 00 00 00 01 7f |.......... |
+--------+-------------------------------------------------+----------------+
io.netty.handler.codec.TooLongFrameException: Adjusted frame length exceeds 1024: 4278190084 - discarded
The reason that writeAndFlush().isSuccess() returns false is that, like all outbound commands, writeAndFlush() is asynchronous. The actual write is done in the channel's event loop thread, and this just hasn't happened yet when you call isSuccess() in the main thread. If you want to block and wait for the write to complete you could use:
channel.writeAndFlush(msg).sync().isSuccess();
The error you see on the server side is because of this frame that arrives before your "this is a test" message:
+-------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------+-------------------------------------------------+----------------+
|00000000| ff 00 00 00 00 00 00 00 01 7f |.......... |
+--------+-------------------------------------------------+----------------+
The LengthFieldBasedFrameDecoder tries to decode the first 4 bytes ff 00 00 00 as the length, which is obviously too large. Do you know what is sending this frame? Could it be your CustomPeerHandler?

Eclipse [] is an unknown syslog facility error

I'm trying to execute a program in eclipse and I when I click run I see this in the console output:
[] is an unknown syslog facility. Defaulting to [USER].
/
"Failed"
Any ideas?
It looks like that error is coming from org.apache.log4j.net.SyslogAppender, and that you've tried to set a bad facility name. Go take a look at your appenders and how you are setting them up.
414 public
415 void setFacility(String facilityName) {
416 if(facilityName == null)
417 return;
418
419 syslogFacility = getFacility(facilityName);
420 if (syslogFacility == -1) {
421 System.err.println("["+facilityName +
422 "] is an unknown syslog facility. Defaulting to [USER].");
423 syslogFacility = LOG_USER;
424 }
425
426 this.initSyslogFacilityStr();
427
428 // If there is already a sqw, make it use the new facility.
429 if(sqw != null) {
430 sqw.setSyslogFacility(this.syslogFacility);
431 }
432 }

Categories