From 1b837fe7ead5c03eeb707d4041f6d7fd11ab7868 Mon Sep 17 00:00:00 2001 From: "PSp..om" Date: Tue, 26 Apr 2011 21:53:49 +0000 Subject: [PATCH] Make client-side background threads daemon. Reduced the amount of logging from invalid UDP messages received. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7314 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/network/base/ConnectorAdapter.java | 2 +- .../com/jme3/network/base/KernelAdapter.java | 6 +++++- .../com/jme3/network/kernel/NamedThreadFactory.java | 13 +++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/engine/src/networking/com/jme3/network/base/ConnectorAdapter.java b/engine/src/networking/com/jme3/network/base/ConnectorAdapter.java index b5ca1b507..2903e77b9 100644 --- a/engine/src/networking/com/jme3/network/base/ConnectorAdapter.java +++ b/engine/src/networking/com/jme3/network/base/ConnectorAdapter.java @@ -82,7 +82,7 @@ public class ConnectorAdapter extends Thread this.reliable = reliable; setDaemon(true); writer = Executors.newFixedThreadPool(1, - new NamedThreadFactory(String.valueOf(connector) + "-writer")); + new NamedThreadFactory(String.valueOf(connector) + "-writer", true)); } public void close() diff --git a/engine/src/networking/com/jme3/network/base/KernelAdapter.java b/engine/src/networking/com/jme3/network/base/KernelAdapter.java index 3a0961648..2ef9f3909 100644 --- a/engine/src/networking/com/jme3/network/base/KernelAdapter.java +++ b/engine/src/networking/com/jme3/network/base/KernelAdapter.java @@ -143,7 +143,11 @@ public class KernelAdapter extends Thread try { HostedConnection source = getConnection(p); if( source == null ) { - log.log( Level.WARNING, "Recieved message from unconnected endpoint:" + p + " message:" + m ); + if( reliable ) { + // If it's a reliable connection then it's slightly more + // concerning but this can happen all the time for a UDP endpoint. + log.log( Level.WARNING, "Recieved message from unconnected endpoint:" + p + " message:" + m ); + } return; } messageDispatcher.messageReceived( source, m ); diff --git a/engine/src/networking/com/jme3/network/kernel/NamedThreadFactory.java b/engine/src/networking/com/jme3/network/kernel/NamedThreadFactory.java index 05cbe52ce..46e0f762f 100644 --- a/engine/src/networking/com/jme3/network/kernel/NamedThreadFactory.java +++ b/engine/src/networking/com/jme3/network/kernel/NamedThreadFactory.java @@ -46,6 +46,7 @@ import java.util.concurrent.ThreadFactory; public class NamedThreadFactory implements ThreadFactory { private String name; + private boolean daemon; private ThreadFactory delegate; public NamedThreadFactory( String name ) @@ -53,9 +54,20 @@ public class NamedThreadFactory implements ThreadFactory this( name, Executors.defaultThreadFactory() ); } + public NamedThreadFactory( String name, boolean daemon ) + { + this( name, daemon, Executors.defaultThreadFactory() ); + } + public NamedThreadFactory( String name, ThreadFactory delegate ) + { + this( name, false, delegate ); + } + + public NamedThreadFactory( String name, boolean daemon, ThreadFactory delegate ) { this.name = name; + this.daemon = daemon; this.delegate = delegate; } @@ -64,6 +76,7 @@ public class NamedThreadFactory implements ThreadFactory Thread result = delegate.newThread(r); String s = result.getName(); result.setName( name + "[" + s + "]" ); + result.setDaemon(daemon); return result; } }