dev@grizzly.java.net

Re: Using Grizzly to capture logs from a Socket

From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Mon, 16 Jul 2007 16:29:06 +0200

Hello Chad,

Grizzly could be used in common manner, not just for HTTP.
For this reason you can look at grizzly-framework module and class
Controller.
You can also take a look at test class: DefaultControllerTest.

If you will have any additional questions - please ask.

WBR,
Alexey.

Chad Gallemore wrote:
>
> Hi,
>
> We are looking to use Grizzly to start up listening on a port and
> accept TCP packets that are sent from a logger
> (java.util.SocketHandler). I am having trouble finding out how exactly
> we accomplish this. I’ve used Grizzly as an http listener, which
> obviously doesn’t work in this situation. Below is what I have now,
> and I am wanting to refactor that out to utilize Grizzly to accomplish
> the same task:
>
> Public static void main (String [] args) {
>
> ServerSocket ss = new ServerSocket(8888);
>
> while (true) {
>
> final Socket socket = ss.accept();
>
> //Spin off a new thread to handle the rest of the processing.
>
> Runnable r = new Runnable() {
>
> public void run() {
>
> try {
>
> processData(socket);
>
> } catch (Exception e) {
>
> e.printStackTrace(); //To change body of catch statement use File |
> Settings | File Templates.
>
> }
>
> }
>
> };
>
> new Thread(r).start();
>
> }
>
> }
>
> Instead I was hoping to do something like the following, with my
> adapter able to handle all of my processing, I later realized this
> won’t work because it only works over HTTP. Is there a way
>
> That I can achieve the same thing over TCP:
>
> Public static void main (String [] args) {
>
> selectorThread.setPort(8888);
>
> selectorThread.setAdapter(new NmrObserverProcessorAdapter(handler));
>
> selectorThread.initEndpoint();
>
> Runnable run = new Runnable() {
>
> public void run() {
>
> try {
>
> System.out.println("starting selector thread endpoint");
>
> selectorThread.startEndpoint();
>
> } catch (Throwable t) {
>
> System.out.println(t);
>
> log.severe("Error starting endpoint for server " + t);
>
> }
>
> }
>
> };
>
> Thread t = new Thread(run);
>
> t.setDaemon(true);
>
> t.start();
>
> }
>
> Thanks for the help.
>
> **Chad**** Gallemore**
>
> 407 Pennsylvania Ave, Suite 201, Joplin, MO 64801
>
> (417) 626-6510 (w)
>
> (909) 528-9405 (c)
>
> (417) 625-1810 (f)
>
> http://gallemore.blogspot.com/
>