Re: Re: Re: Development Framework

Stephen Jackson <[email protected]>
Newsgroups gmane.comp.java.openamf.user
Message-ID <1099716338.2631.96.camel@vaquero>
I don't know anything but the look and feel of your app. but instead of
polling, perhaps this is something to think about.

Perhaps what you could do is separate out the piece of the application
that requires so much communication into it's own .swf.   Then that .swf
makes the call to the app to request the potentially modified data. Add
the thread that makes the request to a List and notifiy the list when
data has been modified,  Add the thread to a List which would own the
threadLock to that object.  Then if the data is modified, notify the
owner of the list (some sort of JMX component - Singleton). It would
update the data, release the threadlock. This way you only have a single
thread polling which some sort of thread that owns the list and the
original thread lock.

Based on the type of data you are asking for use the Observer/Observable
pattern to push your request on a List until the object is notified of a
modification.  Then return the request.

Apparently the end user must be siting there waiting to see constant
changes so it would be constantly connected without constantly asking
for the data.(pop up)?

I attached the working ThreadLock object I have used in the past.  The
concept is there.

Just an idea, would have to prototype it.

public class RequestDataChange{
    private static RequestDataChange = new RequestDataChange();    
    private static Notify notify = new Notify();
    {
        new Thread(notify).run();
    }

    //simplify and make a single for the example
    //JBOSS JMX components work very well
    public static RequestDataChange getInstance(){
        return dataChange;
    }

    //the request thread would call this method
    public waitForUpdate( Data data ){
        try{        
            notify.addData(Data);
            //will block on this until notify thread frees the original
thread lock
            data.getThreadLock();
        }finally{
            data.freeThreadLock();
        }
    }

    //a different thread would update the data
    public void updateData( Object object ){
           notify.updateData(object);
    }

    class Notify implements Runnable {
        private List waitingRoom = new ArrayList();
 
        public void addData( Data data ){
                
                watingRoom.add(data);
                data.getThreadLock();
        }   
        
        public void run(){
            //check
        }

        public updateData( String key, Object newData ){
            //iterate through modifiy the data and release.
            Iterator iter = waitingRoom.iterator();
            while(){
                //update the data 
                //original thread resumes
                data.freeThreadLock();
            }
        }
    }
}

public class Data {
    private HashMap data = new HashMap();
    private ThreadLock lock = new ThreadLock();
    private boolean dataModFlag = false;
    public void lock(){
        lock.getThreadLock();
    }

    public void free(){
        lock.freeThreadLock();
    }

    public boolean getDatModFlag(){
        return this.dataModFlag;
    }

    public void setDataModFlag( boolean flag ){
        this.dataModFlag = flag;
    }
}

On Fri, 2004-11-05 at 00:29, Arif Amirani wrote:

> Hey Stephen,
> 
> I have like 1k clients connected to a DB over OpenAMF and Tomcat on either
> ends (obviously with a Flash client :-)). Now each client can make changes
> to the DB and this needs to be reflected automatically for all the clients.
> 
> Now there are 2 use cases to this:
> 1. Only 1 client is connected to the DB and hence the client unneccessary
> polls for changes.
> 2. 1k of them connect simultaneously and data changes changes rapidly so the
> polling is justified.
> 
> In an event based system, on each data change every client would get
> notified by the server. So no changes no events no requests made. But in
> poll based system my 1k clients make 1k requests every 2 seconds (thats the
> frequency i intend to set). Thats too much!
> 
> So in essence as i posted earlier we need an intelligent polling system and
> the interval should be variable.
> 
> Earlier post sorry to repost.
> "Seems like polling may be the way to go but if I have like 1k clients
> polling unneccessarily to a potentially static data server which may have a
> sudden data change once in a while, it does not sound seriously lucrative.
> 
> I was thinking of designing/implementing an intelligent polling system which
> attaches a probability to the next poll. Depending on this probability the
> client will automatically deduce when to poll next, but I guess such a
> solution is not very generic and scalable.
> 
> I just want to finally have a system that is as efficent as event based
> models and can be implemented using polling."
> 
> Would such a model actually work or im just thinkin too much math :)
> 
> Thanks,
> Arif Amirani.
> 
> "Stephen Jackson" <[email protected]> wrote in message
> news:1099616593.2655.0.camel@vaquero...
> What are you trying to solve?
> 
> On Mon, 2004-11-01 at 04:19, Arif Amirani wrote:
> "is there no way to send a message from server to client?"
> 
> Can somebody please comment on this?
> I am facing imminent polling code to be written if this goes unanswered :)
> 
> Thanks,
> Arif Amirani
> 
> "Ian Pojman" <[email protected]> wrote in message
> news:[email protected]...
> EJBs are good for client/server stuff, for one.... its not the
> programming APIs which you need it for as much as leveraging the
> functionality of an EJB container, that is, writing simple EJB POJOs
> and having the magic 'be worked' underneath you. no rmi programming,
> pooling, etc.
> 
> I guess using OpenAMF is asking for better performance than SOAP...
> that's one of the reasons why I'll most likely stick with OpenAMF...
> 
> is there no way to send a message from server to client?
> 
> 
> On Sun, 31 Oct 2004 19:49:02 +0100, Franois Le Lay <[email protected]> wrote:
> > Yeah actually, the idea is to come up with a richer set of examples than
> > the ones provided in openAMF. As you mentioned it, I also tend to think
> > that one can achieve better performance by avoiding the use of
> > persistance frameworks or EJBs whenever they don't fit the purpose.
> > Actually has anyone here used EJBs rather than JavaBeans/POJOs and for
> > what specific task?
> >
> >
> >
> > Ian Pojman wrote:
> >
> > >I use hibernate and various j2ee stuff but I do not advocate the use
> > >of JBoss or JDO or commons stuff. one can do a lot better without a
> > >bunch of bloaty frameworks...
> > >
> > >really nothing much of j2ee is germane because you can do whatever you
> > >want in your services.
> > >
> > >I would rather see someone show some patterns in using openamf,
> > >examples of more complex AMF conversations.
> > >
> > >/ian
> > >
> > >On Sun, 31 Oct 2004 18:15:33 +0100, Franois Le Lay <[email protected]>
> wrote:
> > >
> > >
> > >>Hi all,
> > >>
> > >>I would like to write a "getting started" doc dealing with the joint use
> > >>of OpenAMF+AS2+JBoss+Eclipse+(JDBC, Commons.DbUtils, JDO, Hibernate). So
> > >>right now I need to know if some of you are using this combiantion of
> > >>tools as their base framework? Could you describe the way you work in a
> > >>few simple steps? I know it sounds like I should be more specific about
> > >>it, but we can get into details later.
> > >>
> > >>Cheers,
> > >>Franois
> > >>
> > >>
> > >>
> >
> > -------------------------------------------------------
> > This SF.Net email is sponsored by:
> > Sybase ASE Linux Express Edition - download now for FREE
> > LinuxWorld Reader's Choice Award Winner for best database on Linux.
> > http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
> > _______________________________________________
> > Openamf-user mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/openamf-user
> >
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Sybase ASE Linux Express Edition - download now for FREE
> LinuxWorld Reader's Choice Award Winner for best database on Linux.
> http://ads.osdn.com/?ad_idU88&alloc_id065&op=ick
> 
> 
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Sybase ASE Linux Express Edition - download now for FREE
> LinuxWorld Reader's Choice Award Winner for best database on Linux.
> http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
> _______________________________________________
> Openamf-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/openamf-user
> 
> 
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Sybase ASE Linux Express Edition - download now for FREE
> LinuxWorld Reader's Choice Award Winner for best database on Linux.
> http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
> _______________________________________________
> Openamf-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/openamf-user
ThreadLock.java (text/x-java, 3.8 KB)
/**
 * A fairly safe way of providing an arbitrary exclusion of code in a
 * multi-threaded environment.
 *WARNING: Since it is fairly easy to use this object to create mutually
 exclusive regions regardless of program flow, it is also
 <i>very,very</i> easy to create deadlocks.  The programmer needs to pay
 special attention to the entry and exit conditions of the region he is
 trying to control.
 *
 */
public class ThreadLock extends Object {
   // instance variables
    private static final boolean DEBUG = false;
    private Thread threadLock = null;
    private int lockCount = 0;

    
    

    /** Gets a threadLock or waits until it is available.  This call is
     * fully blocking, and it uses the tryGetThreadLock method in
     * conjunction with wait() to do its work.
     */
    public synchronized void getThreadLock() {
        if (DEBUG) {
           System.err.println(
           "ThreadLock.getThreadLock entered in " +
           Thread.currentThread().getName()
           ); 
        }

        while (tryGetThreadLock() == false) {
            try {
                if (DEBUG) {
                   System.err.println("!!Waiting on threadLock in " +
                   Thread.currentThread().getName()); 
                }
                wait();
            } catch (Exception e) {
                System.err.println("Caught exception while waiting for threadLock");
            }
        }

        if (DEBUG) {
           System.err.println(
           "ThreadLock.getThreadLock exiting in " +
           Thread.currentThread().getName()
           ); 
        }
    }
    
    /** Gets a busy flag or returns false 
     *@return returns true if one can be obtained right now, false
     otherwise.
     */
    public synchronized boolean tryGetThreadLock() {
        if (DEBUG) {
           System.err.println("ThreadLock.tryGetThreadLock entered in "+
           Thread.currentThread().getName());
        }

        boolean success = false;
        if (threadLock == null) {
            threadLock = Thread.currentThread();
            lockCount = 1;
            success = true;
        } else if (threadLock == Thread.currentThread()) {
            lockCount++;
            success = true;
        }

        if (DEBUG) {
           System.err.println(
           "ThreadLock.tryGetThreadLock exiting in thread "+
           Thread.currentThread().getName() +
           " and lockCount = " + lockCount 
           );
        }

        return success;
    }
    
    /** Frees the threadLock for this owner */ 
    public synchronized void freeThreadLock() {
        if (DEBUG) {
           String lockerName = "";
           if (threadLock != null) {
               lockerName = threadLock.getName();
           }
           System.err.println(
           "ThreadLock.freeThreadLock entered in thread " +
           Thread.currentThread().getName() + 
           " and this lock is owned by " + lockerName); 
        }

        if (getThreadLockOwner() == Thread.currentThread()) {
            lockCount--;
            if (lockCount == 0) {
                threadLock = null;
                notify();
            }
        }

        if (DEBUG) {
           System.err.println(
           "ThreadLock.freeThreadLock exiting in thread " +
           Thread.currentThread().getName() +
           "\n\tlockCount = " + lockCount); 
        }
    }
    
    /** Gets the current owner (Thread) of the threadLock */
    public synchronized Thread getThreadLockOwner() {
        return threadLock;
    }
   /** Returns the number of locks currently held.
    */
   public int getThreadLockCount() {
      return lockCount;
   }
   
    /** Creates new ThreadLock */
    public ThreadLock() {
        if (DEBUG) System.err.println(
           "Lock created in thread " +
           Thread.currentThread().getName() +
           " with lockCount == 0"); 
    }

}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.