Adding Hander Programatically for Embedded (Jetty)

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding Hander Programatically for Embedded (Jetty)

aloleary
Hello,
    Just wondering if anyone knows how I can configure this to work for an embedded Jetty application ?

My code runs fine with the following:

            Server server = new Server(8080);

            ContextHandlerCollection contexts = new ContextHandlerCollection();
            server.setHandler(contexts);

            Context context = new Context(contexts,"/",Context.SESSIONS);
            ServletHolder holder = new ServletHolder();
            holder.setServlet(new ServletAdaptor());
            holder.setInitParameter("com.sun.jersey.config.property.packages", "jerseyswing");
            context.addServlet(holder, "/*");

            Context atmosphereContext = new Context(contexts,"/other",Context.SESSIONS);
            atmosphereContext.addServlet("org.atmosphere.cpr.AtmosphereServlet", "/comet");
            atmosphereContext.setAttribute("delegate", "true");

            // HelloAtmosphereHandler helloAtmosphereHandler = new HelloAtmosphereHandler ();
            // atmosphereContext.addHandler(helloAtmosphereHandler );

            server.start();


But I dont know what do do on the two commented out lines.. obviously atmosphereContext.addHandler wont work as my atmosphere handler implements: AtmosphereHandler<HttpServletRequest,HttpServletResponse>

Any ideas if this is possible ? (im pretty sure the setAttribute above doesnt do anything either)

-A-
Reply | Threaded
Open this post in threaded view
|

Re: Adding Hander Programatically for Embedded (Jetty)

Jeanfrancois Arcand
Salut,

aloleary wrote:

> Hello,
>     Just wondering if anyone knows how I can configure this to work for an
> embedded Jetty application ?
>
> My code runs fine with the following:
>
>             Server server = new Server(8080);
>
>             ContextHandlerCollection contexts = new
> ContextHandlerCollection();
>             server.setHandler(contexts);
>
>             Context context = new Context(contexts,"/",Context.SESSIONS);
>             ServletHolder holder = new ServletHolder();
>             holder.setServlet(new ServletAdaptor());
>            
> holder.setInitParameter("com.sun.jersey.config.property.packages",
> "jerseyswing");
>             context.addServlet(holder, "/*");
>
>             Context atmosphereContext = new
> Context(contexts,"/other",Context.SESSIONS);
>            
> atmosphereContext.addServlet("org.atmosphere.cpr.AtmosphereServlet",
> "/comet");
>             atmosphereContext.setAttribute("delegate", "true");
>
>             // HelloAtmosphereHandler helloAtmosphereHandler = new
> HelloAtmosphereHandler ();
>             // atmosphereContext.addHandler(helloAtmosphereHandler );
>
>             server.start();
>
>
> But I dont know what do do on the two commented out lines.. obviously
> atmosphereContext.addHandler wont work as my atmosphere handler implements:
> AtmosphereHandler<HttpServletRequest,HttpServletResponse>
>
> Any ideas if this is possible ? (im pretty sure the setAttribute above
> doesnt do anything either)

I didn't not think you would like to use it programmaticaly. Do you know
if adding a AtmosphereServlet.addAtmosphereHandler(AtmosphereHandler)
will works for you? I think yes, but just confirm and I will add it and
send you the new cpr jar.

Thanks

-- Jeanfrancois




>
> -A-

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Adding Hander Programatically for Embedded (Jetty)

aloleary
;-) I had just checked out your source code and had refactored mine so I could write:

AtmosphereServlet atmosphereServlet = new AtmosphereServlet();

So right now I cannot do that but it would be great if I could.

Some background:

I have a Swing 'Master' Application that talks to an embedded JavaDB using JPA. This JPA is exposed also using Jersey/REST for small lightweight Swing 'Slaves' - this works quite well - no RMI etc... and I use the same protocols (REST between Master&Slaves as I do between Master+Cloud)

What would be great is if I could enable atmosphere so I can do comet between master and slave as a sort of light weight messaging without doing full embedded JMS -

Not sure if you think this is a good use case !

-A-

Jeanfrancois Arcand wrote
Salut,

aloleary wrote:
> Hello,
>     Just wondering if anyone knows how I can configure this to work for an
> embedded Jetty application ?
>
> My code runs fine with the following:
>
>             Server server = new Server(8080);
>
>             ContextHandlerCollection contexts = new
> ContextHandlerCollection();
>             server.setHandler(contexts);
>
>             Context context = new Context(contexts,"/",Context.SESSIONS);
>             ServletHolder holder = new ServletHolder();
>             holder.setServlet(new ServletAdaptor());
>            
> holder.setInitParameter("com.sun.jersey.config.property.packages",
> "jerseyswing");
>             context.addServlet(holder, "/*");
>
>             Context atmosphereContext = new
> Context(contexts,"/other",Context.SESSIONS);
>            
> atmosphereContext.addServlet("org.atmosphere.cpr.AtmosphereServlet",
> "/comet");
>             atmosphereContext.setAttribute("delegate", "true");
>
>             // HelloAtmosphereHandler helloAtmosphereHandler = new
> HelloAtmosphereHandler ();
>             // atmosphereContext.addHandler(helloAtmosphereHandler );
>
>             server.start();
>
>
> But I dont know what do do on the two commented out lines.. obviously
> atmosphereContext.addHandler wont work as my atmosphere handler implements:
> AtmosphereHandler<HttpServletRequest,HttpServletResponse>
>
> Any ideas if this is possible ? (im pretty sure the setAttribute above
> doesnt do anything either)

I didn't not think you would like to use it programmaticaly. Do you know
if adding a AtmosphereServlet.addAtmosphereHandler(AtmosphereHandler)
will works for you? I think yes, but just confirm and I will add it and
send you the new cpr jar.

Thanks

-- Jeanfrancois




>
> -A-

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@atmosphere.dev.java.net
For additional commands, e-mail: users-help@atmosphere.dev.java.net
Reply | Threaded
Open this post in threaded view
|

Re: Adding Hander Programatically for Embedded (Jetty)

Jeanfrancois Arcand
Salut,

aloleary wrote:
> ;-) I had just checked out your source code and had refactored mine so I
> could write:
>
> AtmosphereServlet atmosphereServlet = new AtmosphereServlet();
>
> So right now I cannot do that but it would be great if I could.

Yes give me 1 hour and your will be able :-)

>
> Some background:
>
> I have a Swing 'Master' Application that talks to an embedded JavaDB using
> JPA. This JPA is exposed also using Jersey/REST for small lightweight Swing
> 'Slaves' - this works quite well - no RMI etc... and I use the same
> protocols (REST between Master&Slaves as I do between Master+Cloud)
>
> What would be great is if I could enable atmosphere so I can do comet
> between master and slave as a sort of light weight messaging without doing
> full embedded JMS -
>
> Not sure if you think this is a good use case !

yes this is a "Comet use case"

Give me 1 hour and I will send you a patch to try.

Thanks!!!!

-- Jeanfrancois



>
> -A-
>
>
> Jeanfrancois Arcand wrote:
>> Salut,
>>
>> aloleary wrote:
>>> Hello,
>>>     Just wondering if anyone knows how I can configure this to work for
>>> an
>>> embedded Jetty application ?
>>>
>>> My code runs fine with the following:
>>>
>>>             Server server = new Server(8080);
>>>
>>>             ContextHandlerCollection contexts = new
>>> ContextHandlerCollection();
>>>             server.setHandler(contexts);
>>>
>>>             Context context = new Context(contexts,"/",Context.SESSIONS);
>>>             ServletHolder holder = new ServletHolder();
>>>             holder.setServlet(new ServletAdaptor());
>>>            
>>> holder.setInitParameter("com.sun.jersey.config.property.packages",
>>> "jerseyswing");
>>>             context.addServlet(holder, "/*");
>>>
>>>             Context atmosphereContext = new
>>> Context(contexts,"/other",Context.SESSIONS);
>>>            
>>> atmosphereContext.addServlet("org.atmosphere.cpr.AtmosphereServlet",
>>> "/comet");
>>>             atmosphereContext.setAttribute("delegate", "true");
>>>
>>>             // HelloAtmosphereHandler helloAtmosphereHandler = new
>>> HelloAtmosphereHandler ();
>>>             // atmosphereContext.addHandler(helloAtmosphereHandler );
>>>
>>>             server.start();
>>>
>>>
>>> But I dont know what do do on the two commented out lines.. obviously
>>> atmosphereContext.addHandler wont work as my atmosphere handler
>>> implements:
>>> AtmosphereHandler<HttpServletRequest,HttpServletResponse>
>>>
>>> Any ideas if this is possible ? (im pretty sure the setAttribute above
>>> doesnt do anything either)
>> I didn't not think you would like to use it programmaticaly. Do you know
>> if adding a AtmosphereServlet.addAtmosphereHandler(AtmosphereHandler)
>> will works for you? I think yes, but just confirm and I will add it and
>> send you the new cpr jar.
>>
>> Thanks
>>
>> -- Jeanfrancois
>>
>>
>>
>>
>>> -A-
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Adding Hander Programatically for Embedded (Jetty)

Jeanfrancois Arcand
Salut,

Jeanfrancois Arcand wrote:

> Salut,
>
> aloleary wrote:
>> ;-) I had just checked out your source code and had refactored mine so I
>> could write:
>>
>> AtmosphereServlet atmosphereServlet = new AtmosphereServlet();
>>
>> So right now I cannot do that but it would be great if I could.
>
> Yes give me 1 hour and your will be able :-)
Attached is the new cpr runtime. The new API looks like:

     /**
      * Add an {@link AtmosphereHandler} serviced by the {@link Servlet}
      * This API is exposed to allow embedding an Atmosphere application.
      * @param The servlet mapping (servlet path)
      * @prama an implementation of an {@link AtmosphereHandler}
      */
     public void addAtmosphereHandler(String mapping, AtmosphereHandler h)

Try it and let me know!

Thanks

-- Jeanfrancois


>
>>
>> Some background:
>>
>> I have a Swing 'Master' Application that talks to an embedded JavaDB
>> using
>> JPA. This JPA is exposed also using Jersey/REST for small lightweight
>> Swing
>> 'Slaves' - this works quite well - no RMI etc... and I use the same
>> protocols (REST between Master&Slaves as I do between Master+Cloud)
>>
>> What would be great is if I could enable atmosphere so I can do comet
>> between master and slave as a sort of light weight messaging without
>> doing
>> full embedded JMS -
>>
>> Not sure if you think this is a good use case !
>
> yes this is a "Comet use case"
>
> Give me 1 hour and I will send you a patch to try.
>
> Thanks!!!!
>
> -- Jeanfrancois
>
>
>
>>
>> -A-
>>
>>
>> Jeanfrancois Arcand wrote:
>>> Salut,
>>>
>>> aloleary wrote:
>>>> Hello,
>>>>     Just wondering if anyone knows how I can configure this to work for
>>>> an
>>>> embedded Jetty application ?
>>>>
>>>> My code runs fine with the following:
>>>>
>>>>             Server server = new Server(8080);
>>>>
>>>>             ContextHandlerCollection contexts = new
>>>> ContextHandlerCollection();
>>>>             server.setHandler(contexts);
>>>>
>>>>             Context context = new
>>>> Context(contexts,"/",Context.SESSIONS);
>>>>             ServletHolder holder = new ServletHolder();
>>>>             holder.setServlet(new ServletAdaptor());
>>>>            
>>>> holder.setInitParameter("com.sun.jersey.config.property.packages",
>>>> "jerseyswing");
>>>>             context.addServlet(holder, "/*");
>>>>
>>>>             Context atmosphereContext = new
>>>> Context(contexts,"/other",Context.SESSIONS);
>>>>            
>>>> atmosphereContext.addServlet("org.atmosphere.cpr.AtmosphereServlet",
>>>> "/comet");
>>>>             atmosphereContext.setAttribute("delegate", "true");
>>>>
>>>>             // HelloAtmosphereHandler helloAtmosphereHandler = new
>>>> HelloAtmosphereHandler ();
>>>>             // atmosphereContext.addHandler(helloAtmosphereHandler );
>>>>
>>>>             server.start();
>>>>
>>>>
>>>> But I dont know what do do on the two commented out lines.. obviously
>>>> atmosphereContext.addHandler wont work as my atmosphere handler
>>>> implements:
>>>> AtmosphereHandler<HttpServletRequest,HttpServletResponse>
>>>>
>>>> Any ideas if this is possible ? (im pretty sure the setAttribute above
>>>> doesnt do anything either)
>>> I didn't not think you would like to use it programmaticaly. Do you
>>> know if adding a
>>> AtmosphereServlet.addAtmosphereHandler(AtmosphereHandler) will works
>>> for you? I think yes, but just confirm and I will add it and send you
>>> the new cpr jar.
>>>
>>> Thanks
>>>
>>> -- Jeanfrancois
>>>
>>>
>>>
>>>
>>>> -A-
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

atmosphere-portable-runtime-0.2-SNAPSHOT.jar (90K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Adding Hander Programatically for Embedded (Jetty)

aloleary
Thanks for that, it works a treat .. now to start building a messaging system around this....

Most of the Atmosphere/Comet examples have the standard chat/html/js clients so need to do a bit of work for a pure java client

I have one question: Is it possible to know if a message is sent to a client or not (reliability?) or is it Best Effort ?

-A-


Jeanfrancois Arcand wrote
Salut,

Jeanfrancois Arcand wrote:
> Salut,
>
> aloleary wrote:
>> ;-) I had just checked out your source code and had refactored mine so I
>> could write:
>>
>> AtmosphereServlet atmosphereServlet = new AtmosphereServlet();
>>
>> So right now I cannot do that but it would be great if I could.
>
> Yes give me 1 hour and your will be able :-)

Attached is the new cpr runtime. The new API looks like:

     /**
      * Add an {@link AtmosphereHandler} serviced by the {@link Servlet}
      * This API is exposed to allow embedding an Atmosphere application.
      * @param The servlet mapping (servlet path)
      * @prama an implementation of an {@link AtmosphereHandler}
      */
     public void addAtmosphereHandler(String mapping, AtmosphereHandler h)

Try it and let me know!

Thanks

-- Jeanfrancois


>
>>
>> Some background:
>>
>> I have a Swing 'Master' Application that talks to an embedded JavaDB
>> using
>> JPA. This JPA is exposed also using Jersey/REST for small lightweight
>> Swing
>> 'Slaves' - this works quite well - no RMI etc... and I use the same
>> protocols (REST between Master&Slaves as I do between Master+Cloud)
>>
>> What would be great is if I could enable atmosphere so I can do comet
>> between master and slave as a sort of light weight messaging without
>> doing
>> full embedded JMS -
>>
>> Not sure if you think this is a good use case !
>
> yes this is a "Comet use case"
>
> Give me 1 hour and I will send you a patch to try.
>
> Thanks!!!!
>
> -- Jeanfrancois
>
>
>
>>
>> -A-
>>
>>
>> Jeanfrancois Arcand wrote:
>>> Salut,
>>>
>>> aloleary wrote:
>>>> Hello,
>>>>     Just wondering if anyone knows how I can configure this to work for
>>>> an
>>>> embedded Jetty application ?
>>>>
>>>> My code runs fine with the following:
>>>>
>>>>             Server server = new Server(8080);
>>>>
>>>>             ContextHandlerCollection contexts = new
>>>> ContextHandlerCollection();
>>>>             server.setHandler(contexts);
>>>>
>>>>             Context context = new
>>>> Context(contexts,"/",Context.SESSIONS);
>>>>             ServletHolder holder = new ServletHolder();
>>>>             holder.setServlet(new ServletAdaptor());
>>>>            
>>>> holder.setInitParameter("com.sun.jersey.config.property.packages",
>>>> "jerseyswing");
>>>>             context.addServlet(holder, "/*");
>>>>
>>>>             Context atmosphereContext = new
>>>> Context(contexts,"/other",Context.SESSIONS);
>>>>            
>>>> atmosphereContext.addServlet("org.atmosphere.cpr.AtmosphereServlet",
>>>> "/comet");
>>>>             atmosphereContext.setAttribute("delegate", "true");
>>>>
>>>>             // HelloAtmosphereHandler helloAtmosphereHandler = new
>>>> HelloAtmosphereHandler ();
>>>>             // atmosphereContext.addHandler(helloAtmosphereHandler );
>>>>
>>>>             server.start();
>>>>
>>>>
>>>> But I dont know what do do on the two commented out lines.. obviously
>>>> atmosphereContext.addHandler wont work as my atmosphere handler
>>>> implements:
>>>> AtmosphereHandler<HttpServletRequest,HttpServletResponse>
>>>>
>>>> Any ideas if this is possible ? (im pretty sure the setAttribute above
>>>> doesnt do anything either)
>>> I didn't not think you would like to use it programmaticaly. Do you
>>> know if adding a
>>> AtmosphereServlet.addAtmosphereHandler(AtmosphereHandler) will works
>>> for you? I think yes, but just confirm and I will add it and send you
>>> the new cpr jar.
>>>
>>> Thanks
>>>
>>> -- Jeanfrancois
>>>
>>>
>>>
>>>
>>>> -A-
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@atmosphere.dev.java.net
>>> For additional commands, e-mail: users-help@atmosphere.dev.java.net
>>>
>>>
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@atmosphere.dev.java.net
> For additional commands, e-mail: users-help@atmosphere.dev.java.net
>

 
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@atmosphere.dev.java.net
For additional commands, e-mail: users-help@atmosphere.dev.java.net
Reply | Threaded
Open this post in threaded view
|

Re: Adding Hander Programatically for Embedded (Jetty)

Jeanfrancois Arcand
Salut,

aloleary wrote:
> Thanks for that, it works a treat .. now to start building a messaging system
> around this....

Great

>
> Most of the Atmosphere/Comet examples have the standard chat/html/js clients
> so need to do a bit of work for a pure java client

Yes I'm also working on a simple that use java.

>
> I have one question: Is it possible to know if a message is sent to a client
> or not (reliability?) or is it Best Effort ?

In order to do that right now you will need to implement yourself a
Broadcaster:

https://atmosphere.dev.java.net/nonav/apidocs/org/atmosphere/cpr/Broadcaster.html

that track messages sent (or add a special header to track where the
client is). It's one of my goal to add this features by default in
Atmosphere BTW. Most probably version 0.3 will have it.

Does that help?

Thanks!

-- Jeanfrancois


>
> -A-
>
>
>
> Jeanfrancois Arcand wrote:
>> Salut,
>>
>> Jeanfrancois Arcand wrote:
>>> Salut,
>>>
>>> aloleary wrote:
>>>> ;-) I had just checked out your source code and had refactored mine so I
>>>> could write:
>>>>
>>>> AtmosphereServlet atmosphereServlet = new AtmosphereServlet();
>>>>
>>>> So right now I cannot do that but it would be great if I could.
>>> Yes give me 1 hour and your will be able :-)
>> Attached is the new cpr runtime. The new API looks like:
>>
>>      /**
>>       * Add an {@link AtmosphereHandler} serviced by the {@link Servlet}
>>       * This API is exposed to allow embedding an Atmosphere application.
>>       * @param The servlet mapping (servlet path)
>>       * @prama an implementation of an {@link AtmosphereHandler}
>>       */
>>      public void addAtmosphereHandler(String mapping, AtmosphereHandler h)
>>
>> Try it and let me know!
>>
>> Thanks
>>
>> -- Jeanfrancois
>>
>>
>>>> Some background:
>>>>
>>>> I have a Swing 'Master' Application that talks to an embedded JavaDB
>>>> using
>>>> JPA. This JPA is exposed also using Jersey/REST for small lightweight
>>>> Swing
>>>> 'Slaves' - this works quite well - no RMI etc... and I use the same
>>>> protocols (REST between Master&Slaves as I do between Master+Cloud)
>>>>
>>>> What would be great is if I could enable atmosphere so I can do comet
>>>> between master and slave as a sort of light weight messaging without
>>>> doing
>>>> full embedded JMS -
>>>>
>>>> Not sure if you think this is a good use case !
>>> yes this is a "Comet use case"
>>>
>>> Give me 1 hour and I will send you a patch to try.
>>>
>>> Thanks!!!!
>>>
>>> -- Jeanfrancois
>>>
>>>
>>>
>>>> -A-
>>>>
>>>>
>>>> Jeanfrancois Arcand wrote:
>>>>> Salut,
>>>>>
>>>>> aloleary wrote:
>>>>>> Hello,
>>>>>>     Just wondering if anyone knows how I can configure this to work
>>>>>> for
>>>>>> an
>>>>>> embedded Jetty application ?
>>>>>>
>>>>>> My code runs fine with the following:
>>>>>>
>>>>>>             Server server = new Server(8080);
>>>>>>
>>>>>>             ContextHandlerCollection contexts = new
>>>>>> ContextHandlerCollection();
>>>>>>             server.setHandler(contexts);
>>>>>>
>>>>>>             Context context = new
>>>>>> Context(contexts,"/",Context.SESSIONS);
>>>>>>             ServletHolder holder = new ServletHolder();
>>>>>>             holder.setServlet(new ServletAdaptor());
>>>>>>            
>>>>>> holder.setInitParameter("com.sun.jersey.config.property.packages",
>>>>>> "jerseyswing");
>>>>>>             context.addServlet(holder, "/*");
>>>>>>
>>>>>>             Context atmosphereContext = new
>>>>>> Context(contexts,"/other",Context.SESSIONS);
>>>>>>            
>>>>>> atmosphereContext.addServlet("org.atmosphere.cpr.AtmosphereServlet",
>>>>>> "/comet");
>>>>>>             atmosphereContext.setAttribute("delegate", "true");
>>>>>>
>>>>>>             // HelloAtmosphereHandler helloAtmosphereHandler = new
>>>>>> HelloAtmosphereHandler ();
>>>>>>             // atmosphereContext.addHandler(helloAtmosphereHandler );
>>>>>>
>>>>>>             server.start();
>>>>>>
>>>>>>
>>>>>> But I dont know what do do on the two commented out lines.. obviously
>>>>>> atmosphereContext.addHandler wont work as my atmosphere handler
>>>>>> implements:
>>>>>> AtmosphereHandler<HttpServletRequest,HttpServletResponse>
>>>>>>
>>>>>> Any ideas if this is possible ? (im pretty sure the setAttribute above
>>>>>> doesnt do anything either)
>>>>> I didn't not think you would like to use it programmaticaly. Do you
>>>>> know if adding a
>>>>> AtmosphereServlet.addAtmosphereHandler(AtmosphereHandler) will works
>>>>> for you? I think yes, but just confirm and I will add it and send you
>>>>> the new cpr jar.
>>>>>
>>>>> Thanks
>>>>>
>>>>> -- Jeanfrancois
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> -A-
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>>>>
>>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>  
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Adding Hander Programatically for Embedded (Jetty)

aloleary
Cheers,
That really helps a lot
-A-


Jeanfrancois Arcand wrote
Salut,

aloleary wrote:
> Thanks for that, it works a treat .. now to start building a messaging system
> around this....

Great

>
> Most of the Atmosphere/Comet examples have the standard chat/html/js clients
> so need to do a bit of work for a pure java client

Yes I'm also working on a simple that use java.

>
> I have one question: Is it possible to know if a message is sent to a client
> or not (reliability?) or is it Best Effort ?

In order to do that right now you will need to implement yourself a
Broadcaster:

https://atmosphere.dev.java.net/nonav/apidocs/org/atmosphere/cpr/Broadcaster.html

that track messages sent (or add a special header to track where the
client is). It's one of my goal to add this features by default in
Atmosphere BTW. Most probably version 0.3 will have it.

Does that help?

Thanks!

-- Jeanfrancois


>
> -A-
>
>
>
> Jeanfrancois Arcand wrote:
>> Salut,
>>
>> Jeanfrancois Arcand wrote:
>>> Salut,
>>>
>>> aloleary wrote:
>>>> ;-) I had just checked out your source code and had refactored mine so I
>>>> could write:
>>>>
>>>> AtmosphereServlet atmosphereServlet = new AtmosphereServlet();
>>>>
>>>> So right now I cannot do that but it would be great if I could.
>>> Yes give me 1 hour and your will be able :-)
>> Attached is the new cpr runtime. The new API looks like:
>>
>>      /**
>>       * Add an {@link AtmosphereHandler} serviced by the {@link Servlet}
>>       * This API is exposed to allow embedding an Atmosphere application.
>>       * @param The servlet mapping (servlet path)
>>       * @prama an implementation of an {@link AtmosphereHandler}
>>       */
>>      public void addAtmosphereHandler(String mapping, AtmosphereHandler h)
>>
>> Try it and let me know!
>>
>> Thanks
>>
>> -- Jeanfrancois
>>
>>
>>>> Some background:
>>>>
>>>> I have a Swing 'Master' Application that talks to an embedded JavaDB
>>>> using
>>>> JPA. This JPA is exposed also using Jersey/REST for small lightweight
>>>> Swing
>>>> 'Slaves' - this works quite well - no RMI etc... and I use the same
>>>> protocols (REST between Master&Slaves as I do between Master+Cloud)
>>>>
>>>> What would be great is if I could enable atmosphere so I can do comet
>>>> between master and slave as a sort of light weight messaging without
>>>> doing
>>>> full embedded JMS -
>>>>
>>>> Not sure if you think this is a good use case !
>>> yes this is a "Comet use case"
>>>
>>> Give me 1 hour and I will send you a patch to try.
>>>
>>> Thanks!!!!
>>>
>>> -- Jeanfrancois
>>>
>>>
>>>
>>>> -A-
>>>>
>>>>
>>>> Jeanfrancois Arcand wrote:
>>>>> Salut,
>>>>>
>>>>> aloleary wrote:
>>>>>> Hello,
>>>>>>     Just wondering if anyone knows how I can configure this to work
>>>>>> for
>>>>>> an
>>>>>> embedded Jetty application ?
>>>>>>
>>>>>> My code runs fine with the following:
>>>>>>
>>>>>>             Server server = new Server(8080);
>>>>>>
>>>>>>             ContextHandlerCollection contexts = new
>>>>>> ContextHandlerCollection();
>>>>>>             server.setHandler(contexts);
>>>>>>
>>>>>>             Context context = new
>>>>>> Context(contexts,"/",Context.SESSIONS);
>>>>>>             ServletHolder holder = new ServletHolder();
>>>>>>             holder.setServlet(new ServletAdaptor());
>>>>>>            
>>>>>> holder.setInitParameter("com.sun.jersey.config.property.packages",
>>>>>> "jerseyswing");
>>>>>>             context.addServlet(holder, "/*");
>>>>>>
>>>>>>             Context atmosphereContext = new
>>>>>> Context(contexts,"/other",Context.SESSIONS);
>>>>>>            
>>>>>> atmosphereContext.addServlet("org.atmosphere.cpr.AtmosphereServlet",
>>>>>> "/comet");
>>>>>>             atmosphereContext.setAttribute("delegate", "true");
>>>>>>
>>>>>>             // HelloAtmosphereHandler helloAtmosphereHandler = new
>>>>>> HelloAtmosphereHandler ();
>>>>>>             // atmosphereContext.addHandler(helloAtmosphereHandler );
>>>>>>
>>>>>>             server.start();
>>>>>>
>>>>>>
>>>>>> But I dont know what do do on the two commented out lines.. obviously
>>>>>> atmosphereContext.addHandler wont work as my atmosphere handler
>>>>>> implements:
>>>>>> AtmosphereHandler<HttpServletRequest,HttpServletResponse>
>>>>>>
>>>>>> Any ideas if this is possible ? (im pretty sure the setAttribute above
>>>>>> doesnt do anything either)
>>>>> I didn't not think you would like to use it programmaticaly. Do you
>>>>> know if adding a
>>>>> AtmosphereServlet.addAtmosphereHandler(AtmosphereHandler) will works
>>>>> for you? I think yes, but just confirm and I will add it and send you
>>>>> the new cpr jar.
>>>>>
>>>>> Thanks
>>>>>
>>>>> -- Jeanfrancois
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> -A-
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@atmosphere.dev.java.net
>>>>> For additional commands, e-mail: users-help@atmosphere.dev.java.net
>>>>>
>>>>>
>>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@atmosphere.dev.java.net
>>> For additional commands, e-mail: users-help@atmosphere.dev.java.net
>>>
>>  
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@atmosphere.dev.java.net
>> For additional commands, e-mail: users-help@atmosphere.dev.java.net
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@atmosphere.dev.java.net
For additional commands, e-mail: users-help@atmosphere.dev.java.net