felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rcbandit2 <peter.pen...@gmail.com>
Subject Re: How to add Java network server into OSGI bundle
Date Fri, 10 Feb 2012 18:29:06 GMT

This is my simple example of OSGI bundle:
http://www.2shared.com/file/h6lFjppY/CB_27.html
Where I have to put the source code of the java network server in order to
work?



nfndx wrote:
> 
> It does not seem like you need your network server to be a osgi service.
> So
> if you just need your network server to be started then create a osgi
> bundle. Also create an activator for this bundle( remember to set this
> activator in the manifest) . In the start method if the activator you
> should be able to start your network server
> 
> Hope that helps
> Regards
> Ivanhoe
> On Feb 10, 2012 5:32 PM, "rcbandit2" <peter.penzov@gmail.com> wrote:
> 
>>
>> Any ideas or reply?
>>
>>
>>
>> rcbandit2 wrote:
>> >
>> > Hi,
>> >
>> > I created this Java network server:
>> >
>> > import java.net.*;
>> > import java.io.*;
>> >
>> > public class EchoServer
>> > {
>> > ServerSocket m_ServerSocket;
>> >
>> > public EchoServer()
>> > {
>> > try
>> > {
>> > // Create the server socket.
>> > m_ServerSocket = new ServerSocket(12111);
>> > }
>> > catch(IOException ioe)
>> > {
>> > System.out.println("Could not create server socket at 12111.
>> Quitting.");
>> > System.exit(-1);
>> > }
>> >
>> > System.out.println("Listening for clients on 12111...");
>> >
>> > // Successfully created Server Socket. Now wait for connections.
>> > int id = 0;
>> > while(true)
>> > {
>> > try
>> > {
>> > // Accept incoming connections.
>> > Socket clientSocket = m_ServerSocket.accept();
>> >
>> > ClientServiceThread cliThread = new ClientServiceThread(clientSocket,
>> > id++);
>> > cliThread.start();
>> > }
>> > catch(IOException ioe)
>> > {
>> > System.out.println("Exception encountered on accept. Ignoring. Stack
>> Trace
>> > :");
>> > ioe.printStackTrace();
>> > }
>> > }
>> > }
>> >
>> > public static void main (String[] args)
>> > {
>> > new EchoServer();
>> > }
>> >
>> > class ClientServiceThread extends Thread
>> > {
>> > Socket m_clientSocket;
>> > int m_clientID = -1;
>> > boolean m_bRunThread = true;
>> >
>> > ClientServiceThread(Socket s, int clientID)
>> > {
>> > m_clientSocket = s;
>> > m_clientID = clientID;
>> > }
>> >
>> > public void run()
>> > {
>> > // Obtain the input stream and the output stream for the socket
>> > // A good practice is to encapsulate them with a BufferedReader
>> > // and a PrintWriter as shown below.
>> > BufferedReader in = null;
>> > PrintWriter out = null;
>> >
>> > // Print out details of this connection
>> > System.out.println("Accepted Client : ID - " + m_clientID + " : Address
>> -
>> > " +
>> > m_clientSocket.getInetAddress().getHostName());
>> >
>> > try
>> > {
>> > in = new BufferedReader(new
>> > InputStreamReader(m_clientSocket.getInputStream()));
>> > out = new PrintWriter(new
>> > OutputStreamWriter(m_clientSocket.getOutputStream()));
>> >
>> > // At this point, we can read for input and reply with appropriate
>> output.
>> >
>> > // Run in a loop until m_bRunThread is set to false
>> > while(m_bRunThread)
>> > {
>> > // read incoming stream
>> > String clientCommand = in.readLine();
>> >
>> > System.out.println("Client Says :" + clientCommand);
>> >
>> > if(clientCommand.equalsIgnoreCase("quit"))
>> > {
>> > // Special command. Quit this thread
>> > m_bRunThread = false;
>> > System.out.print("Stopping client thread for client : " + m_clientID);
>> > }
>> > else
>> > {
>> > // Echo it back to the client.
>> > out.println(clientCommand);
>> > out.flush();
>> > }
>> > }
>> > }
>> > catch(Exception e)
>> > {
>> > e.printStackTrace();
>> > }
>> > finally
>> > {
>> > // Clean up
>> > try
>> > {
>> > in.close();
>> > out.close();
>> > m_clientSocket.close();
>> > System.out.println("...Stopped");
>> > }
>> > catch(IOException ioe)
>> > {
>> > ioe.printStackTrace();
>> > }
>> > }
>> > }
>> > }
>> > }
>> >
>> > I want to insert this code into OSGI bundle. At the moment I don't have
>> > configured Glassfish with datasource to test the bundle. What I have to
>> do
>> > in order to configure the Java server to listen for incomming
>> connections
>> > when I deploy it on Glassfish server?
>> >
>> > Do I need to add somenthing into the OSGI bundle activator to make the
>> > Java server listen for incomming connections?
>> >
>> > Best Wishes
>> >
>>
>> --
>> View this message in context:
>> http://old.nabble.com/How-to-add-Java-network-server-into-OSGI-bundle-tp33295152p33301156.html
>> Sent from the Apache Felix - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/How-to-add-Java-network-server-into-OSGI-bundle-tp33295152p33302398.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Mime
View raw message