How can I stop HL7Server ? I start it in a new thread,but I can not stop it.

View: New views
7 Messages — Rating Filter:   Alert me  

How can I stop HL7Server ? I start it in a new thread,but I can not stop it.

by Yu Gu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,
I start HL7Server in a new thread, but I don't know how to stop it.
I write the code like this:

class ServerSubThread
      extends Thread {
    public void run() {          
        startProvidingService();
    }
 }
ServerSubThread sst = new ServerSubThread();

public void startService(){
       sst.start();
}
public void stopService(){
      if (isRunning()) {
             hl7server.stop();
     }
}

public void startProvidingService() {
    ServerSocket ss = null;
    ss = new ServerSocket(this.port);
    ..................................
    hl7server = new HL7Server(ss, ari, safestorage);
    Processor processor = null;
    processor = hl7server.accept(null);
   hl7server.start(null);              
}

when stopService method is called,it does not stop the server,for it can still receive the connection and response the sendAndReceive method from client .
Should I end all the thread started by ServerSubThread ? How can I do that ?  
Thanks. Any help is appreciative.
Yu
Just Do It !

Re: How can I stop HL7Server ? I start it in a new thread,but I can not stop it.

by Yu Gu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all, I add the operation of closing the socket, so method is changed like this:

public void stopService(){
  try{
      if (isRunning()) {
             hl7server.stop();
     }
     if(ss != null){
            ss.close();
     }
   }
  catch (IOException ioex) {
      ioex.printStackTrace();
    }
}

It can refuse next connection because the socket has been closed.
Just Do It !

Re: How can I stop HL7Server ? I start it in a new thread,but I can not stop it.

by Yu Gu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi , I find when I close the socket in order to stop the HL7Server,it catch the exception as follows:

 (0 ms) [Thread-6] ERROR: ca.uhn.hl7v2.protocol.impl.ServerSocketStreamSource$Acc
eptor#error : Error accepting remote connection
java.net.SocketException: socket closed
        at java.net.PlainSocketImpl.socketAccept(Native Method)
        at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384)
        at java.net.ServerSocket.implAccept(ServerSocket.java:453)
        at java.net.ServerSocket.accept(ServerSocket.java:421)
        at ca.uhn.hl7v2.protocol.impl.ServerSocketStreamSource$Acceptor$1.run(ServerSocketStreamSource.java:115)
        at java.lang.Thread.run(Thread.java:619)
.................

But if I don't close the socket, when I stop the HL7Server by calling hl7server.stop() method, it can still work because the HL7Server is waiting for accepting next connection.

It seems dilemma to me...  What should I do?

Thanks in advance! Any help is appreciative.
Just Do It !

Re: How can I stop HL7Server ? I start it in a new thread,but I can not stop it.

by nksharma0624 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The code inside the "ServerSocketStreamSource" need some addtion:

before calling the acceptor...isLCosed() method shall be called.

This will not allow to open a new socket for new connection request on this server socket.

while ((a.getSocket() == null) && (!theServer.isClosed())) {
.........

Hope thhis make sense.

-Niranjan.
Yu Gu wrote:
Hi all,
I start HL7Server in a new thread, but I don't know how to stop it.
I write the code like this:

class ServerSubThread
      extends Thread {
    public void run() {          
        startProvidingService();
    }
 }
ServerSubThread sst = new ServerSubThread();

public void startService(){
       sst.start();
}
public void stopService(){
      if (isRunning()) {
             hl7server.stop();
     }
}

public void startProvidingService() {
    ServerSocket ss = null;
    ss = new ServerSocket(this.port);
    ..................................
    hl7server = new HL7Server(ss, ari, safestorage);
    Processor processor = null;
    processor = hl7server.accept(null);
   hl7server.start(null);              
}

when stopService method is called,it does not stop the server,for it can still receive the connection and response the sendAndReceive method from client .
Should I end all the thread started by ServerSubThread ? How can I do that ?  
Thanks. Any help is appreciative.
Yu

Re: How can I stop HL7Server ? I start it in a new thread,but I can not stop it.

by Yu Gu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,Niranjan,thank you for your rapid reply! You help me a lot!

But how can I modify it? It is "Read only to protect against modification" when I import HAPI-0.5.1 jar into my project.  Is there any other way to stop hl7server?

Thanks a lot!

Best regards
Yu
Just Do It !

Re: How can I stop HL7Server ? I start it in a new thread, but I can not stop it.

by nksharma0624 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Either you download the source code yourself and build yourself for your
needs.

Else Submit a bug report and HAPI team will take an action when it
reaches to this bug.

Hope this make sense.

Best Regards
-Niranjan.

-----Original Message-----
From: Yu Gu [mailto:guyucowboy@...]
Sent: Tuesday, September 01, 2009 8:37 PM
To: hl7api-devel@...
Subject: Re: [HAPI-devel] How can I stop HL7Server ? I start it in a new
thread, but I can not stop it.


Hi,Niranjan,thank you for your rapid reply! You help me a lot!

But how can I modify it? It is "Read only to protect against
modification"
when I import HAPI-0.5.1 jar into my project.  Is there any other way to
stop hl7server?

Thanks a lot!

Best regards
Yu

-----
Just Do It !
--
View this message in context:
http://www.nabble.com/How-can-I-stop-HL7Server---I-start-it-in-a-new-thr
ead%2Cbut-I-can-not-stop-it.-tp24365555p25250756.html
Sent from the hl7api-devel mailing list archive at Nabble.com.


------------------------------------------------------------------------
------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and
focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@...
https://lists.sourceforge.net/lists/listinfo/hl7api-devel

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@...
https://lists.sourceforge.net/lists/listinfo/hl7api-devel

Re: How can I stop HL7Server ? I start it in a new thread, but I can not stop it.

by Yu Gu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,Niranjan. I modify the code and build it.
Before I modify the code ,when closing the socket, the exception information occurs every minute(for there is sentence:Thread.sleep(1000);). Now the exception information occurs just once. It is acceptable I think.

Maybe the exception is inevitable if I close the socket,because the sentence "s = theServer.accept();" will suspend to wait for and accept next connection in the while loop. So when socket is closed, it would throw exception.

Best Regards
Yu
Just Do It !