Hi Vin,

ULC follows the request-response architecture. Requests are initiated from
the client and the server (the ULC application) just responds to those
requests.  The server does not block when it sends requests to the client.
The client can block on the requests sent to the server depending on the
event delivery mode.

In general, return value from a call to the client can be obtained on the
server in an event handler for the event generated from the client.

I have modified your code. Kindly see the snippet below.

Thanks and regards,

Janak

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Vin Addala
Sent: Thursday, January 18, 2007 8:49 AM
To: [email protected]
Subject: [ULC-developer] Synchronize client and server threads


Hi ULC Users,

I am trying to write a small program to check if a file exists on the
client. I have created server side and client side code. On the client side
I create a file object and check for file.exists(); I will eventually use
the File object for other purposes like canRead, canWrite etc.

The problem I am having is that the server thread and the client threads are
not synchronized. I get a response back from the server before the client
checks if the file exists. I need server to wait for the client thread to
finish before it returns. In my test program, the "file exists" test result
comes back as false (default boolean value) and gets printed to system.out.
Once the TestProxy.start() method finishes the client side method
checkIsExists(...) gets invoked and returns true back to the
ULCFileUtilties.setIsFileExists(..). But this response is not caught and
returned to the test program.

Any help is appreciated in helping me figure out how I can block the server
from proceeding until the client finishes checking. I have tried setUIState,
fireActionPerformedULC, but nothing seems to work.

Thank You for your help,
Vin

------------------------


import java.io.File;

import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.ApplicationContext;
import com.ulcjava.base.application.ULCProxy;
import com.ulcjava.base.application.event.ActionEvent;
import com.ulcjava.base.application.event.IActionListener;
import com.ulcjava.base.client.UIProxy;
import com.ulcjava.base.development.DevelopmentRunner;
import com.ulcjava.base.shared.UlcEventCategories;
import com.ulcjava.base.shared.UlcEventConstants;


public class TestFileExists extends AbstractApplication {
    public void start() {
        ULCFileUtilities proxy = new ULCFileUtilities("c:\\test.txt");
        proxy.checkIsExists();
    }

    public static void main(String[] args) {
        DevelopmentRunner.setApplicationClass(TestFileExists.class);
        DevelopmentRunner.run();
    }


    public static class ULCFileUtilities extends ULCProxy {
        private String fileName;
        private boolean isFileExists = false;

        public ULCFileUtilities(String fileName) {
            setEventDeliveryMode(UlcEventCategories.ACTION_EVENT_CATEGORY,
UlcEventConstants.SYNCHRONOUS_MODE);
            this.fileName = fileName;
            addActionListener(new IActionListener() {
                public void actionPerformed(ActionEvent event) {
                    setIsFileExists(event.getActionCommand().equals("exists"
));
                    System.out.println("File exists result: " +
getIsFileExists());
                    ApplicationContext.terminate();
                }
            });
            markUncollectable();
            upload();
        }

        public void checkIsExists() {
            Object[] fileNames = new Object[] { fileName };
            invokeUI("checkIsExists", fileNames);
        }

        protected String typeString() {
            return UIFileUtilities.class.getName();
        }

        public void setIsFileExists(boolean isExists) {
            isFileExists = isExists;
        }

        public boolean getIsFileExists() {
            return isFileExists;
        }

        public void addActionListener(IActionListener actionListener) {
            addListener(UlcEventCategories.ACTION_EVENT_CATEGORY,
actionListener);
        }

        public void removeActionListener(IActionListener actionListener) {
            removeListener(UlcEventCategories.ACTION_EVENT_CATEGORY,
actionListener);
        }

    }


    public static class UIFileUtilities extends UIProxy {
        public UIFileUtilities() {
        }

        public void checkIsExists(String fileName) {
            File file = new File(fileName);
            if (file.exists()) {
                fireActionPerformedULC("exists", 0);
            } else {
                fireActionPerformedULC("notexists", 0);
            }
        }
    }
}

_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to