Thread: [Simpleweb-Support] How to get noticed when Simple Server goes down ...
Brought to you by:
niallg
|
From: bagas <ba...@in...> - 2004-05-10 07:31:10
|
Hi,
Currently I use Simple as simple as this ..
Connection webserverConn = ConnectionFactory.getConnection(new
HttpMainHandler(), new BufferedPipelineFactory(4096));
webserverConn.connect(new ServerSocket(80));
class HttpMainHandler implements ProtocolHandler {
public void handle(Request req, Response resp) {
//do something //
}
}
is it running ServerSocket(80).close() would stop this server cleanly?
Supposed ServerSocket(80) crashes because of any problem, how to get a
noticed when this event occur?
Thank you
|
|
From: Niall G. <nia...@an...> - 2004-05-10 09:28:15
|
Hi, > is it running ServerSocket(80).close() would stop this server cleanly? Not exactly, you need a handle on the ServerSocket given to the Connection.connect method. So if you did this ServerSocket sock = new ServerSocket(80); Connection.connect(sock); // whatever .... sock.close() // terminates the connection ... > Supposed ServerSocket(80) crashes because of any problem, how to get a > noticed when this event occur? You would need to write a simple.http.connect.SocketHandler to use with a Connection object. You can introduce your own functionality to handle failures. Niall |
|
From: bagas <ba...@in...> - 2004-05-11 03:57:06
|
>Hi,
>> is it running ServerSocket(80).close() would stop this server
cleanly?
> Not exactly, you need a handle on the ServerSocket given to the
> Connection.connect method. So if you did this
> ServerSocket sock = new ServerSocket(80);
> Connection.connect(sock);
> // whatever ....
> sock.close() // terminates the connection ...
Okay thank you ...
>> Supposed ServerSocket(80) crashes because of any problem, how to get
a
>> noticed when this event occur?
> You would need to write a simple.http.connect.SocketHandler to use
with
> a Connection object. You can introduce your own functionality to
handle
> failures.
> Niall
If I am not mistaken, implementing simple.http.connect.SocketHandler can
only be used after the ServerSocket accepts a connection and makes a
Socket to handle the connection.
But what I want is, to detect whether ServerSocket is still
listening/accepting or not. I don't think implementing
simple.http.connect.SocketHandler would solve this because the
ServerSocket is not accepting a connection (no Socket given to
SocketHandler yet).
I currently use code like this to check whether ServerSocket is still
listening/accepting or not!!
new Thread()
{
public void run()
{
while(true)
{
if((!sock.isBound) || sock.isClosed())
{
// do something to restart the web
server
}
Thread.sleep(5000);
}
}
}
Could you advice me better solution ?
Thank you
Best Regard,
Rahmat Bagas Santoso
|
|
From: Niall G. <nia...@an...> - 2004-05-11 09:13:09
|
Hi,
> If I am not mistaken, implementing simple.http.connect.SocketHandler can
> only be used after the ServerSocket accepts a connection and makes a
> Socket to handle the connection.
>
> But what I want is, to detect whether ServerSocket is still
> listening/accepting or not. I don't think implementing
> simple.http.connect.SocketHandler would solve this because the
> ServerSocket is not accepting a connection (no Socket given to
> SocketHandler yet).
In this case what you could do is extend the ServerSocket, this may not
be the most elegant solution but it is quite easy. Try somthing like
public class MonitoredServerSocket extends ServerSocket {
private Monitor monitor;
public MonitoredServerSocket(Monitor monitor, int port) {
super(port);
this.monitor = monitor;
}
public Socket accept() throws IOException {
try {
return super.accept();
} catch(IOException e){
monitor.notifyException(this, e);
throw e;
}
}
}
public interface Monitor {
public void notifyException(ServerSocket sock, IOException e);
}
At least this way you can still use the ConnectionFactory without having
to recode your own connection framework.
Hope this is of use,
Niall
|
|
From: bagas <ba...@in...> - 2004-05-11 10:18:53
|
I currently init Https like this :
String source = "keystore";
char[] storePassword = {'p'};
char[] keyPassword = {'p'};
KeyStore store = KeyStore.getInstance("JKS");
store.load(new FileInputStream(source), storePassword);
KeyManagerFactory keyFactory =
KeyManagerFactory.getInstance("SunX509");
keyFactory.init(store, keyPassword);
SSLContext sslContext = SSLContext.getInstance("SSLv3");
sslContext.init(keyFactory.getKeyManagers(), null, null);
ServerSocketFactory socketFactory = sslContext.getServerSocketFactory();
Server.connection.connect(socketFactory.createServerSocket(sslPort));
If I want to use interface Monitor (like you advice earlier for
ServerSocket), how can I do that?
Thank you very much
Regards,
Rahmat Bagas Santoso
> In this case what you could do is extend the ServerSocket, this may
not
> be the most elegant solution but it is quite easy. Try somthing like
> public class MonitoredServerSocket extends ServerSocket {
> private Monitor monitor;
> public MonitoredServerSocket(Monitor monitor, int port) {
> super(port);
> this.monitor = monitor;
> }
> public Socket accept() throws IOException {
> try {
> return super.accept();
> } catch(IOException e){
> monitor.notifyException(this, e);
> throw e;
> }
> }
> }
> public interface Monitor {
>
> public void notifyException(ServerSocket sock, IOException e);
> }
|
|
From: Niall G. <nia...@an...> - 2004-05-11 11:08:27
|
Hi,
> Server.connection.connect(socketFactory.createServerSocket(sslPort));
>
> If I want to use interface Monitor (like you advice earlier for
> ServerSocket), how can I do that?
Mabye try and wrap the socketFactory.createServerSocket(sslPort) within
the ServerSocket implementation and delegate to the created SSLServerSocket
like this.
Server.connection.connect(new MonitoredServerSocket(monitor, socketFactory.createServerSocket(sslPort)));
public class MonitoredServerSocket extends ServerSocket {
private Monitor monitor;
private ServerSocket sock;
public MonitoredServerSocket(Monitor monitor, ServerSocket sock){
this.monitor = monitor;
this.sock = sock;
}
public boolean isClosed() {
return sock.isClosed();
}
public Socket accept() throws IOException {
try {
return sock.accept();
}catch(IOException e){
// as before ...
}
}
}
This should work....
Niall
|
|
From: bagas <ba...@in...> - 2004-05-13 04:16:13
|
Hi,
Thanks you very much It work perfectly... I have other questions though
..
1. For the SSL Socket wraper, is there any situation that I should wrap
another method?
2. I am using Simple for SMPP to HTTP gateway so it is designed to be
able receive lots connection with relatively small data to be passed
around. So far I use Simple like this :
webserverConn =
new Connection(new SocketHandler(
PipelineHandlerFactory.getInstance(new HttpMainHandler()),
new BufferedPipelineFactory(2096))));
Could you advice me better solution ?
Thank you again.
Regards,
Rahmat Bagas Santoso
-----Original Message-----
From: sim...@li...
[mailto:sim...@li...] On Behalf Of
Niall Gallagher
Sent: Tuesday, May 11, 2004 6:08 PM
To: sim...@li...
Subject: RE: [Simpleweb-Support] How to get noticed when
SimpleServergoesdown ...
Hi,
> Server.connection.connect(socketFactory.createServerSocket(sslPort));
>
> If I want to use interface Monitor (like you advice earlier for
> ServerSocket), how can I do that?
Mabye try and wrap the socketFactory.createServerSocket(sslPort) within
the ServerSocket implementation and delegate to the created
SSLServerSocket
like this.
Server.connection.connect(new MonitoredServerSocket(monitor,
socketFactory.createServerSocket(sslPort)));
public class MonitoredServerSocket extends ServerSocket {
private Monitor monitor;
private ServerSocket sock;
public MonitoredServerSocket(Monitor monitor, ServerSocket sock){
this.monitor = monitor;
this.sock = sock;
}
public boolean isClosed() {
return sock.isClosed();
}
public Socket accept() throws IOException {
try {
return sock.accept();
}catch(IOException e){
// as before ...
}
}
}
This should work....
Niall
-------------------------------------------------------
This SF.Net email is sponsored by Sleepycat Software
Learn developer strategies Cisco, Motorola, Ericsson & Lucent use to
deliver higher performing products faster, at low TCO.
http://www.sleepycat.com/telcomwpreg.php?From=osdnemail3
_______________________________________________
Simpleweb-Support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simpleweb-support
|
|
From: Niall G. <nia...@an...> - 2004-05-13 10:19:42
|
Hi > 1. For the SSL Socket wraper, is there any situation that I should wrap > another method? Not as far as Simple is concerned, the only methods used by the simple.http.connect package are the ServerSocket.accept() and ServerSocket.isClosed(). However you may want to override the ServerSocket.close() method if you wish to terminate a connection. > 2. I am using Simple for SMPP to HTTP gateway so it is designed to be > able receive lots connection with relatively small data to be passed > around. So far I use Simple like this : > webserverConn = > new Connection(new SocketHandler( > PipelineHandlerFactory.getInstance(new HttpMainHandler()), > new BufferedPipelineFactory(2096)))); If the messages and responses are small then perhaps a BufferedPipelineFactory using 2K is too much, this will only help on pipelines where it will get allot of reuse across many requests. Apart from that I think you will probably know what is best! You may also want to look at the other PipelineHandlerFactory.getInstance method which will allow you to tweak the polling configuration. Regards, Niall |