[Red5] Red5.getConnectionLocal() from SchedulerJob returns null
Mamontov Sergey V.
moonlight at ua.elro.com
Tue Nov 20 08:46:32 PST 2007
Still nothing :(
Thanks who try to help me with this useless Scheduler, it can't be
used for our main target.
Now I've returned to ServerStream. There is only one thing witch don't
allow us to use PlayList fully.
After above 60 seconds of streaming increasing latency, and at the end
of playback it looks really strange.
Our target is to: paste to non registered users every 30 seconds some
promo, and controling when was played first 30 seconds for signed up
users.
Can anybody handle in this question?
Thanks,
Sergey
> No, there is no local connection to the thread. You scheduled the thread
> through the services. This is normal. It will be null.
> Id do something like this to make it work real fast, but their might be
> better ways.
> public void streamPlaylistItemPlay(IPlaylistSubscriberStream stream,
> IPlayItem item, boolean isLive)
> {
> Red5.getConnectionLocal().GetClient().setAttribute("playing",item.name);
> PLaylistTimer PLayTimer=new
> PLaylistTimer(Red5.getConnectionLocal().GetClient().getScope());
> String jobname=addscheduledJob(10000, PLayTimer)
> PlayTimer.name= jobname;
> Red5.getConnectionLocal().GetClient().setAttribute("jobname", jobname);
>
> }
> Then your thread execute
> Iterator<IConnection>clientSet=m_r5IScope.getConnections();
>
> while(clientSet.hasNext())
> {
> IConnection c=clientSet.next();
> try
> {
>
> if(c.getcClient().getAttribute("jobname","").equals(this.name))
> red5.getconnectionlocal().close();//or Pause
> }
> -----Original Message-----
> From: red5-bounces at osflash.org [mailto:red5-bounces at osflash.org] On
> Behalf Of Mamontov Sergey V.
> Sent: Monday, November 19, 2007 10:33 PM
> To: Andy
> Subject: Re: [Red5] Red5.getConnectionLocal() from SchedulerJob returns
> null
> Andy,
> Yes, this works great :)
> But if I try call from execute some function of my application, for
> example:
> public void testMethod(IConnection conn){
> log.info("Getting connection. Connection is: "
> +Red5.getConnectionLocal()) //<- Getting connection. Connection is:
> null
> log.info("Application IConnect: "+conn) //<- it will trace needed
> connection, but doesn't have accesses to already created Clients,
> connections.
> }
> I can get may variables and that's all what is possible
> to do.
> Andy, try make something like this and you will understand me :) Try
> for example pause VOD playback :)
> Regards,
> Sergey
>> Sergey
>> I have created a class on the server to represent the client , holding
>> all his important stuff, as well as a reference to the IConnection.
>> The list arrays make this work very easy, and I have even implemented
>> the very use you describe. But there is a better way.
>> The easier way is for your IScheduledJob class to take the Application
>> scope or some scope in the constructor, and store a reference. When it
>> is executed, it already has all the clients and connections for the
>> scope it was given.
>> -----Original Message-----
>> From: red5-bounces at osflash.org [mailto:red5-bounces at osflash.org] On
>> Behalf Of Mamontov Sergey V.
>> Sent: Monday, November 19, 2007 1:19 PM
>> To: kyoung wan park
>> Subject: Re: [Red5] Red5.getConnectionLocal() from SchedulerJob
> returns
>> null
>> Kyoun,
>> Who told You that? :)
>> If my Streamer extends ApplicationAdapter, he also implements all of
> his
>> methods, and methods of MultithreadApplicationAdapter :)
>> Someone explain me, what Scheduling service invoking already in other
>> thread, so it haven't access to all IConnection what was created in
>> previous thread :(
>> I see only on possible solution, not very elegance, but i think it
> will
>> work, I will use SharedObject and events for it. When scheduler will
>> execute, he will write some flag to corresponding user, meantime main
>> application have listeners on shardeobject change. Listener will
> iterate
>> through all connection and search user whom sharedobject was changed
> in
>> the connection of application and then invoke corresponding actions.
>> This is really not very good, but only one right solution for
> situation,
>> when after executing of scheduler I need to to do something with
> client
>> playback.
>> I will accept any possible variations on this theme :)
>> Regards,
>> Sergey
>>> Why next code is possible
>>> it is because Application class implements ISchedulingService
>> interface
>>> Application app = (Application)service;
>>
>>> but your streamer not implement that interface
>>> so your code not permited
>>
>>> I'm sorry I can't help you
>>
>>
>>> Date: Mon, 19 Nov 2007 22:02:42 +0200
>>> From: moonlight at ua.elro.com
>>> To: red5 at osflash.org
>>> Subject: Re: [Red5] Red5.getConnectionLocal() from SchedulerJob
>> returns null
>>>
>>> Hi Kyoung,
>>>
>>> Thanks for example, but i still can't make it work well :(
>>> This is my code for ScheduledJob:
>>>
>>> class myJob30sec implements IScheduledJob{
>>>
>>> private Streamer application;
>>> private IScope cscope;
>>> private static final Log log = LogFactory.getLog(myJob30sec.class);
>>>
>>> public myJob30sec(Streamer app, IScope scope){
>>> cscope = scope;
>>> application = app;
>>> }
>>>
>>> public void execute(ISchedulingService service) throws
>>> CloneNotSupportedException {
>>> Iterator<IConnection> iter = application.getConnectionsIter();
>>> while (iter.hasNext()) {
>>> IConnection conn = iter.next();
>>> if (conn.getScope().equals(cscope))
>>> {
>>> IStreamService pservice = (IStreamService)
>> conn.getScope().getContext().getBean(IStreamService.BEAN_NAME);
>>> log.info("@_scheduler_@ service name "+pservice);
>>> pservice.seek(80000);
>>> }
>>> log.info("hi connection");
>>> }
>>> }
>>> }
>>>
>>>
>>> When I start job, I pass to it my main application named "Streamer",
>> and scope of current user ( they can be many ).
>>>
>>> In result I need to make some action with stream, which is currently
>> playing for selected user, for example seek forward on 80 seconds.
>>>
>>> When I trying do something like this in myJob30sec:
>>> Streamer app = (Streamer)service;
>>> the error appear, that:
>>> Job com.ppfm.myJob30sec at 14c0275 execution failed:
>> org.red5.server.scheduling.QuartzSchedulingService cannot be cast to
>> com.ppfm.Streamer
>>>
>>> If it possible, someone help me, or soon I will be punished.
>>>
>>>
>>> Regards,
>>>
>>>
>>> Sergey
>>>
>>>
>>>
>>> >
>>> > hi John
>>> >
>>> > you can access Application via IScheduleJob interface,
>>> > but except a few method of StreamService, i think you can not
>>> > access Appilcation via IStreamService
>>> >
>>> > next code is works
>>> > test it and find your answer
>>> >
>>> > public class DummyScheduleJob implements IScheduledJob {
>>> > private static final Log log =
> LogFactory.getLog(Application.class);
>>> > public void execute(ISchedulingService service)
>>> > throws CloneNotSupportedException {
>>> > // TODO Auto-generated method stub
>>> > log.info("dummy schedule joing executed");
>>> > Application app = (Application)service;
>>> > Iterator<IConnection> iter = app.getConnectionsIter();
>>> > while (iter.hasNext()) {
>>> > IConnection conn = iter.next();
>>> > log.info("hi connection");
>>> > }
>>> > }
>>> > }
>>> >
>>>
>>> >
>>> >
>>> >
>>>
>>> > Date: Sun, 18 Nov 2007 12:35:34 +0200
>>> > From: moonlight at ua.elro.com
>>> > To: red5 at osflash.org
>>> > Subject: Re: [Red5] Red5.getConnectionLocal() from SchedulerJob
>> returns null
>>>
>>> >
>>>
>>> > John,
>>> >
>>>
>>> > Hello :)
>>> > I still don't understand how to make custom events in application.
>>> > And after I found attribute with of corresponding JobName, how can
> I
>>> > invoke to pause sever stream exactly for this client?
>>> >
>>>
>>> > P.S. maybe someone found better solution, maybe native for Red5,
>> this will be great :)
>>> >
>>>
>>> > Regards,
>>> >
>>>
>>> > Sergey
>>> >
>>>
>>> > >
>>> > I looked at the title of this email and I did a double take
>>> > because I had a "saved" email that I was going to send later with
>>> > pretty much the Exact title. =) I thought gmail accidently sent my
>> saved email hahaha
>>> >
>>>
>>> > anyway, I found that the way Red5.getconnectionlocal() works only
>>> > allows the local Thread to the IConnection to have access. Since
>>> > SchedulerJob is a completely separate thread, it does not had
> access
>> to IConnection.
>>> >
>>>
>>> > I havent found a good solution for this yet, but for now Im
>>> > setting an attribute to the IClient at appconnect and on the
>>> > execute() method I loop through the client for the matching
>> attribute and do my thing.
>>> >
>>>
>>> >
>>>
>>> >
>>>
>>> >
>>>
>>> > On Nov 16, 2007 9:22 AM, Mamontov Sergey V. <moonlight at ua.elro.com>
>> wrote:
>>> >
>>>
>>> > Hi,
>>> >
>>>
>>> > During me development I've discovered some new strange thing. When
>> I'm
>>> > trying to add some Scheduler in my application, calling of
>>> > Red5.getConnectionLocal(); return me "null" as connection, when
>>> > calling it from body of ShedulerJob, mean time, same call in main
>>> > class return me connection info.
>>> >
>>>
>>> > This is small, but main part of class, witch causing strange
>> behavior.
>>> >
>>>
>>> > public class CustomStreamService extends StreamService implements
>> IScheduledJob {
>>> >
>>>
>>> > public void play (String name){
>>> >
>>>
>>> > IConnection conn = Red5.getConnectionLocal();
>>> > ISchedulingService service = (ISchedulingService)
>>> > conn.getScope().getContext().getBean(ISchedulingService.BEAN_NAME
> );
>>> > ClientData client =
>>> > ((ClientData)conn.getClient().getAttribute("client"));
>>> > String clientId = client.getId();
>>> > log.info("@_StreamService_@ Connection info: "+conn); //<- works
>>> > great ("Connection RTMPMinaConnection from XX.XXX.XXX.XXX:1245 to
>>> > XX.XXX.XXX.XXX (in: 3719, out: 5329) ")
>>> > startPlayBackWatcher();
>>> > }
>>> >
>>>
>>> > public void startPlayBackWatcher(){
>>> >
>>>
>>> > IConnection conn = Red5.getConnectionLocal();
>>> > ISchedulingService service = (ISchedulingService)
>>> > conn.getScope().getContext().getBean(ISchedulingService.BEAN_NAME);
>>> > ClientData client =
>>> > ((ClientData)conn.getClient().getAttribute("client"));
>>> > String jobName1 = service.addScheduledOnceJob(5000, this);
>>> > }
>>> >
>>>
>>> > public void execute(ISchedulingService service) throws
>>> > CloneNotSupportedException {
>>> > IConnection conn = Red5.getConnectionLocal ();
>>> > pause(true, 15000);
>>> > log.info("@_StreamService_@ Connection info: "+conn); //<-
>>> > doesn't work :( ( return "null")
>>> > }
>>> >
>>>
>>> > What is wrong in my code? Please, help me :)
>>> > P.S. Actually I'm not really good Java developer, Flash is My life
>>> > :)
>>> >
>>>
>>> >
>>>
>>> > Regards,
>>> >
>>>
>>> > Sergey
>>> >
>>>
>>> >
>>>
>>> > _______________________________________________
>>> > Red5 mailing list
>>> > Red5 at osflash.org
>>> > http://osflash.org/mailman/listinfo/red5_osflash.org
>>> >
>>>
>>> >
>>>
>>> >
>>>
>>> >
>>>
>>> > --
>>> > ?? ???????????,
>>> > Mamontov mailto:moonlight at ua.elro.com
>>>
>>>
>>> > Explore the seven wonders of the world Learn more!
>>>
>>>
>>> _______________________________________________
>>> Red5 mailing list
>>> Red5 at osflash.org
>>> http://osflash.org/mailman/listinfo/red5_osflash.org
>> Explore the seven wonders of the world Learn more!
>> _______________________________________________
>> Red5 mailing list
>> Red5 at osflash.org
>> http://osflash.org/mailman/listinfo/red5_osflash.org
> _______________________________________________
> Red5 mailing list
> Red5 at osflash.org
> http://osflash.org/mailman/listinfo/red5_osflash.org
More information about the Red5
mailing list