[logback-dev] svn commit: r1470 - in logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse: reciever views
noreply.seb at qos.ch
noreply.seb at qos.ch
Wed Mar 28 11:43:27 CEST 2007
Author: seb
Date: Wed Mar 28 11:43:27 2007
New Revision: 1470
Modified:
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/reciever/SocketNode.java
logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java
Log:
Better management of the socket server
Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java Wed Mar 28 11:43:27 2007
@@ -22,6 +22,7 @@
private int port = 4321;
private ServerSocket serverSocket;
+ private boolean stop = false;
public SimpleSocketServer() {
}
@@ -41,6 +42,7 @@
public void restart() {
try {
serverSocket.close();
+ stop = false;
startAndLoop();
} catch (IOException e) {
PluginLogger.logError(e);
@@ -48,12 +50,14 @@
}
private void startAndLoop() {
+ stop = false;
try {
serverSocket = new ServerSocket(port);
- while (true) {
+ while (!stop) {
Socket socket = serverSocket.accept();
new Thread(new SocketNode(socket)).start();
}
+ serverSocket.close();
} catch (java.net.BindException e) {
String errorMessage = "The port " + port + " is already in use.";
PluginLogger.logError(errorMessage, e);
@@ -80,7 +84,7 @@
}
}
- public boolean isPortFree() {
+ public static boolean isPortFree(Integer port) {
try {
Socket s = new Socket("localhost", port);
return !s.isConnected();
@@ -88,5 +92,9 @@
return true;
}
}
+
+ public void stop() {
+ stop = true;
+ }
}
Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/reciever/SocketNode.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/reciever/SocketNode.java (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/reciever/SocketNode.java Wed Mar 28 11:43:27 2007
@@ -23,17 +23,22 @@
Socket socket;
ObjectInputStream ois;
+ boolean oisInError = false;
public SocketNode(Socket socket) {
this.socket = socket;
try {
ois = new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));
} catch (Exception e) {
-
+ oisInError = true;
}
}
public void run() {
+ if (oisInError) {
+ return;
+ }
+
LoggingEvent event;
try {
Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java (original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java Wed Mar 28 11:43:27 2007
@@ -1,5 +1,6 @@
package ch.qos.logback.eclipse.views;
+import java.net.Socket;
import java.net.URL;
import org.eclipse.jface.action.Action;
@@ -181,14 +182,6 @@
}
- private void launchSocketServer(Integer port) {
- server = new SimpleSocketServer();
- if (port != null) {
- server.setPort(port.intValue());
- }
- startServerThread(server);
- }
-
@Override
public void setFocus() {
viewer.getControl().setFocus();
@@ -199,6 +192,7 @@
super.dispose();
provider.dispose();
labelProvider.dispose();
+ server.stop();
}
public int getServerPort() {
@@ -214,8 +208,25 @@
viewer.refresh();
}
- public void updateServerPort(Integer serverPort) {
- launchSocketServer(serverPort);
+ public void updateServerPort(Integer port) {
+ if (port != null) {
+ if (SimpleSocketServer.isPortFree(port)) {
+ server.stop();
+ openAndCloseClientToServer();
+ serverThread.interrupt();
+ serverThread = null;
+ server.setPort(port);
+ startServerThread(server);
+ }
+ }
+ }
+
+ private void openAndCloseClientToServer() {
+ try {
+ Socket s = new Socket("localhost", server.getPort());
+ } catch (Exception e) {
+ //do nothing
+ }
}
private void initServer() {
@@ -227,7 +238,7 @@
}
private void startServerThread(SimpleSocketServer server) {
- if (server.isPortFree()) {
+ if (SimpleSocketServer.isPortFree(server.getPort())) {
serverThread = new Thread(server);
serverThread.start();
PluginLogger.logInfo("Now listening on port: " + server.getPort());
More information about the logback-dev
mailing list