I think its an issue of threading on server side.

This is how it works for me !!! By clicking on button "Get Service
message".

Let me know if it works for you.

+Bakul Kumar+

//Client side code :
public class POC implements EntryPoint {

        Label lblMessage;
        Timer timer = new Timer() {
                public void run() {
                        StockServiceAsync service = new StockServiceRPC()
                                .getStockServiceAsync();
                        service.getMessage(new AsyncCallback<String>(){
                                public void onSuccess(String result) {
                                        lblMessage.setText("Comp Message : " + 
result);
                                }

                                public void onFailure(Throwable caught) {
                                                Window.alert("Call Failed on 
Server");
                                }
                        });
                };
        };

        public void onModuleLoad() {
                Image img = new Image(
                                
"http://code.google.com/webtoolkit/logo-185x175.png";);
                Button button = new Button("Click me");


                button.addStyleName("pc-template-btn");

                img.getElement().setId("pc-template-img");

                VerticalPanel vPanel = new VerticalPanel();
                vPanel.setWidth("100%");
                vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
                vPanel.add(img);
                vPanel.add(button);

                Button serviceButton = new Button("Get Service Message");
                vPanel.add(serviceButton);
                serviceButton.addClickListener(new ClickListener() {
                        public void onClick(Widget sender) {
                                timer.scheduleRepeating(1000);
                                StockServiceAsync service = new 
StockServiceRPC()
                                                .getStockServiceAsync();  
//This one do the job of setting the
entry point for RPC call
                                service.longComputation(new 
AsyncCallback<String>() {
                                        public void onSuccess(String result) {
                                                timer.cancel();
                                                Window.alert("Long Comp Message 
: " + result);
                                        }


                                        public void onFailure(Throwable caught) 
{
                                                timer.cancel();
                                                Window.alert("Call Failed on 
Server");
                                        }
                                });
                        }
                });

                lblMessage = new Label("Message");
                vPanel.add(lblMessage);

                // Add image and button to the RootPanel
                RootPanel.get().add(vPanel);

                // Create the dialog box
                final DialogBox dialogBox = new DialogBox();
                dialogBox.setText("Welcome to GWT!");
                dialogBox.setAnimationEnabled(true);
                Button closeButton = new Button("close");
                VerticalPanel dialogVPanel = new VerticalPanel();
                dialogVPanel.setWidth("100%");
                dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
                dialogVPanel.add(closeButton);

                closeButton.addClickListener(new ClickListener() {
                        public void onClick(Widget sender) {
                                dialogBox.hide();
                        }
                });

                // Set the contents of the Widget
                dialogBox.setWidget(dialogVPanel);

                button.addClickListener(new ClickListener() {
                        public void onClick(Widget sender) {
                                dialogBox.center();
                                dialogBox.show();
                        }
                });
        }
}


////////////Server side code


public class StockServiceImpl extends RemoteServiceServlet implements
                StockService {

        private static final long serialVersionUID = 1L;

        String message;

        public StockPrice getPrices(String[] symbols) {
                return new StockPrice("LEH", 0.0);
        }

        public String longComputation(){

                for(long i = 0; i < 10; i++){
                        message = " Iteration # " + i;
                        try {
                                Thread.sleep(2000);
                        } catch (InterruptedException e) {
                                e.printStackTrace();
                        }
                }

                return "BK Rocks !!!, Calculation Completes";
        }

        public String getMessage(){
                final StringBuffer myMessage = new StringBuffer();
                Thread t = new Thread(){
                        @Override
                        public void run() {
                                myMessage.append(message);;

                        }
                };
                t.start();

                while(myMessage.length() == 0){
                        //wait till the message is being set
                }

                return myMessage.toString();
        }
}

On Sep 23, 8:38 am, Palietta <[EMAIL PROTECTED]> wrote:
> Here is a sample. It might contain errors but displays what I
> basically tried to do.
>
> // Obviously there is an asynchronous version of this interface
> public interface MyService extends RemoteService {
>         public String requestStatusMessage();
>
>         public void doLengthyComputation();
>
> }
>
> MyServiceAsync service = (MyServiceAsync) GWT.create(MyService.class);
> Timer t = new MyTimer();
>
> public void callMainService() {
>         t.scheduleRepeating(1000);
>         ServiceDefTarget endpoint = (ServiceDefTarget) service;
>         endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "mymodule");
>         AsyncCallback<String> callback = new AsyncCallback<String>() {
>                 // whatever the outcome, stop the polling timer
>                 public void onFailure(Throwable caught) {
>                         t.cancel();
>                         // do something to show failure
>                 }
>
>                 public void onSuccess(String result) {
>                         t.cancel();
>                         // do something else
>                 }
>                 // start the polling timer right before calling the main 
> service
>                 t.run();
>                 service.doLengthyComputation();
>
> }
>
> public class MyTimer extends Timer {
>         public void run() {
>                 poll();
>         }
>
>         public void poll() {
>                 ServiceDefTarget endpoint = (ServiceDefTarget) service;
>                 endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + 
> "mymodule");
>                 AsyncCallback<String> callback = new AsyncCallback<String>() {
>                         public void onFailure(Throwable caught) {
>                                 System.out.println("polling failed");
>                         }
>
>                         public void onSuccess(String result) {
>                                 System.out.println(result);
>                         }
>                 service.requestStatusMessage();
>         }
>
> }
>
> On 23 Set, 13:17, Lothar Kimmeringer <[EMAIL PROTECTED]> wrote:
>
> > Hello,
>
> > Palietta schrieb:
>
> > > So I created a client-side Timer which, every second, polls another
> > > remote service that simply returns this state variable. This timer is
> > > started right before the main service is called, and is halted after
> > > the service returns.
>
> > > Being these calls asynchronous, this method didn't work. All scheduled
> > > Timer calls returned after the main service altogether.
>
> > > I know it might be a dumb question, but it would really be helpful for
> > > me to be able to provide the user with continued feedback on the state
> > > of the service they called.
>
> > Can you provide some source how you call the long running task
> > and create the timer? I have some ideas why this fails, but
> > it's only guessing without knowing more.
>
> > Independent from that you might google for "Comet GWT". This
> > might be a solution for you as well.
>
> > Regards, Lothar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to