summaryrefslogtreecommitdiff
path: root/java/demo
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2009-12-03 17:09:19 +0100
committerBenoit Foucher <benoit@zeroc.com>2009-12-03 17:09:19 +0100
commitf24200b2f2ce752ac2d35751d6d615b72642bbaf (patch)
treec1d95a4b55725bac4c1115e9b76e9718f1396ad7 /java/demo
parentAdded back IceHome setting for source tree compiles (diff)
downloadice-f24200b2f2ce752ac2d35751d6d615b72642bbaf.tar.bz2
ice-f24200b2f2ce752ac2d35751d6d615b72642bbaf.tar.xz
ice-f24200b2f2ce752ac2d35751d6d615b72642bbaf.zip
Fixed demos to use Ice.Dispatcher
Diffstat (limited to 'java/demo')
-rw-r--r--java/demo/Glacier2/chat/Client.java147
-rw-r--r--java/demo/Ice/applet/HelloApplet.java86
-rw-r--r--java/demo/Ice/swing/Client.java85
3 files changed, 109 insertions, 209 deletions
diff --git a/java/demo/Glacier2/chat/Client.java b/java/demo/Glacier2/chat/Client.java
index fbd3aa7c8a1..859aa1617a4 100644
--- a/java/demo/Glacier2/chat/Client.java
+++ b/java/demo/Glacier2/chat/Client.java
@@ -54,8 +54,6 @@ import Ice.LocalException;
import Ice.StringSeqHolder;
import Ice.Util;
-// TODO: Simplify the callbacks when http://bugzilla/bugzilla/show_bug.cgi?id=4193 is fixed.
-
@SuppressWarnings("serial")
public class Client extends JFrame
{
@@ -137,14 +135,7 @@ public class Client extends JFrame
public void
exception(final LocalException ex)
{
- SwingUtilities.invokeLater(new Runnable() {
-
- public void
- run()
- {
- appendMessage("<system-message> - " + ex);
- }
- });
+ appendMessage("<system-message> - " + ex);
}
});
}
@@ -311,90 +302,82 @@ public class Client extends JFrame
_connectionPanel.add(fieldPanel);
_input.setEnabled(false);
- Ice.Properties properties = Ice.Util.createProperties();
- properties.load("config.client");
+
+ Ice.InitializationData initData = new Ice.InitializationData();
+
+ // Load the configuration file.
+ initData.properties = Ice.Util.createProperties();
+ initData.properties.load("config.client");
StringSeqHolder argHolder = new StringSeqHolder(args);
- properties = Util.createProperties(argHolder, properties);
- _factory = new SessionFactoryHelper(properties, new SessionCallback()
+ initData.properties = Util.createProperties(argHolder, initData.properties);
+
+ // Setup a dispatcher to dispath Ice and Glacier2 helper callbacks to the GUI thread.
+ initData.dispatcher = new Ice.Dispatcher()
+ {
+ public void
+ dispatch(Runnable runnable, Ice.Connection connection)
+ {
+ SwingUtilities.invokeLater(runnable);
+ }
+ };
+
+ _factory = new SessionFactoryHelper(initData, new SessionCallback()
+ {
+ public void
+ connected(SessionHelper session)
+ throws SessionNotExistException
{
- // The session helper callbacks are all called from the
- // GUI thread.
- public void
- connected(SessionHelper session)
- throws SessionNotExistException
+ // If the session has been reassigned avoid the spurious callback.
+ if(session != _session)
{
- // If the session has been reassigned avoid the
- // spurious callback.
- if(session != _session)
- {
- return;
+ return;
+ }
+
+ // The chat callback servant. We use an anonymous
+ // inner class since the implementation is very
+ // simple.
+ Demo._ChatCallbackDisp servant = new Demo._ChatCallbackDisp()
+ {
+ public void
+ message(final String data, Current current)
+ {
+ appendMessage(data);
}
+ };
- // The chat callback servant. We use an anonymous
- // inner class since the implementation is very
- // simple.
- Demo._ChatCallbackDisp servant = new Demo._ChatCallbackDisp()
- {
- public void
- message(final String data, Current current)
- {
- SwingUtilities.invokeLater(new Runnable()
- {
- public void
- run()
- {
- appendMessage(data);
- }
- });
- }
- };
- Demo.ChatCallbackPrx callback = Demo.ChatCallbackPrxHelper.uncheckedCast(
- _session.addWithUUID(servant));
+ Demo.ChatCallbackPrx callback = Demo.ChatCallbackPrxHelper.uncheckedCast(_session.addWithUUID(servant));
- _chat = Demo.ChatSessionPrxHelper.uncheckedCast(_session.session());
- _chat.begin_setCallback(callback, new Demo.Callback_ChatSession_setCallback()
+ _chat = Demo.ChatSessionPrxHelper.uncheckedCast(_session.session());
+ _chat.begin_setCallback(callback, new Demo.Callback_ChatSession_setCallback()
+ {
+ @Override
+ public void
+ response()
{
- @Override
- public void
- response()
- {
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- assert _loginDialog != null;
- _loginDialog.dispose();
-
- _login.setEnabled(false);
- _logout.setEnabled(true);
-
- _input.setEnabled(true);
-
- _status.setText("Connected with " + _hostField.getText());
- }
- });
- }
+ assert _loginDialog != null;
+ _loginDialog.dispose();
+
+ _login.setEnabled(false);
+ _logout.setEnabled(true);
+
+ _input.setEnabled(true);
+
+ _status.setText("Connected with " + _hostField.getText());
+ }
- @Override
- public void
- exception(LocalException ex)
- {
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- destroySession();
- }
- });
- }
- });
+ @Override
+ public void
+ exception(LocalException ex)
+ {
+ destroySession();
+ }
+ });
}
public void
disconnected(SessionHelper session)
{
- // If the session has been reassigned avoid the
- // spurious callback.
+ // If the session has been reassigned avoid the spurious callback.
if(session != _session)
{
return;
@@ -455,7 +438,7 @@ public class Client extends JFrame
_factory.setRouterHost(_hostField.getText());
// Connect to Glacier2 using SessionFactoryHelper
_session = _factory.connect(_userNameField.getText(), _passwordField.getText());
- String[] cancel = {"Cancel" };
+ String[] cancel = { "Cancel" };
// Show Connecting Dialog
JOptionPane pane = new JOptionPane("Please wait while connecting...", JOptionPane.INFORMATION_MESSAGE,
diff --git a/java/demo/Ice/applet/HelloApplet.java b/java/demo/Ice/applet/HelloApplet.java
index 34f52fd23c9..ea3837f5289 100644
--- a/java/demo/Ice/applet/HelloApplet.java
+++ b/java/demo/Ice/applet/HelloApplet.java
@@ -43,6 +43,14 @@ public class HelloApplet extends JApplet
Ice.InitializationData initData = new Ice.InitializationData();
initData.properties = Ice.Util.createProperties();
initData.properties.load("config.applet");
+ initData.dispatcher = new Ice.Dispatcher()
+ {
+ public void
+ dispatch(Runnable runnable, Ice.Connection connection)
+ {
+ SwingUtilities.invokeLater(runnable);
+ }
+ };
_communicator = Ice.Util.initialize(initData);
}
catch(Throwable ex)
@@ -322,13 +330,7 @@ public class HelloApplet extends JApplet
String host = _hostname.getText().toString().trim();
if(host.length() == 0)
{
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- _status.setText("No hostname");
- }
- });
+ _status.setText("No hostname");
return null;
}
@@ -352,13 +354,7 @@ public class HelloApplet extends JApplet
{
assert (!_response);
_response = true;
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- _status.setText("Ready");
- }
- });
+ _status.setText("Ready");
}
@Override
@@ -366,14 +362,7 @@ public class HelloApplet extends JApplet
{
assert (!_response);
_response = true;
-
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- handleException(ex);
- }
- });
+ handleException(ex);
}
@Override
@@ -384,20 +373,14 @@ public class HelloApplet extends JApplet
return;
}
- SwingUtilities.invokeLater(new Runnable()
+ if(_deliveryMode == DeliveryMode.TWOWAY || _deliveryMode == DeliveryMode.TWOWAY_SECURE)
{
- public void run()
- {
- if(_deliveryMode == DeliveryMode.TWOWAY || _deliveryMode == DeliveryMode.TWOWAY_SECURE)
- {
- _status.setText("Waiting for response");
- }
- else
- {
- _status.setText("Ready");
- }
- }
- });
+ _status.setText("Waiting for response");
+ }
+ else
+ {
+ _status.setText("Ready");
+ }
}
}
@@ -450,25 +433,13 @@ public class HelloApplet extends JApplet
@Override
public void response()
{
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- _status.setText("Ready");
- }
- });
+ _status.setText("Ready");
}
@Override
public void exception(final Ice.LocalException ex)
{
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- handleException(ex);
- }
- });
+ handleException(ex);
}
});
if(_deliveryMode == DeliveryMode.TWOWAY || _deliveryMode == DeliveryMode.TWOWAY_SECURE)
@@ -501,13 +472,7 @@ public class HelloApplet extends JApplet
}
catch(final Ice.LocalException ex)
{
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- handleException(ex);
- }
- });
+ handleException(ex);
}
}
}).start();
@@ -550,14 +515,7 @@ public class HelloApplet extends JApplet
private void handleException(final Throwable ex)
{
ex.printStackTrace();
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- _status.setText(ex.getClass().getName());
- }
- }
- );
+ _status.setText(ex.getClass().getName());
}
private static class SliderListener implements ChangeListener
diff --git a/java/demo/Ice/swing/Client.java b/java/demo/Ice/swing/Client.java
index 1c758cb621d..ffdac41877e 100644
--- a/java/demo/Ice/swing/Client.java
+++ b/java/demo/Ice/swing/Client.java
@@ -70,6 +70,14 @@ public class Client extends JFrame
Ice.InitializationData initData = new Ice.InitializationData();
initData.properties = Ice.Util.createProperties();
initData.properties.load("config.client");
+ initData.dispatcher = new Ice.Dispatcher()
+ {
+ public void
+ dispatch(Runnable runnable, Ice.Connection connection)
+ {
+ SwingUtilities.invokeLater(runnable);
+ }
+ };
_communicator = Ice.Util.initialize(args, initData);
}
catch(Throwable ex)
@@ -371,13 +379,7 @@ public class Client extends JFrame
String host = _hostname.getText().toString().trim();
if(host.length() == 0)
{
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- _status.setText("No hostname");
- }
- });
+ _status.setText("No hostname");
return null;
}
@@ -399,13 +401,7 @@ public class Client extends JFrame
{
assert (!_response);
_response = true;
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- _status.setText("Ready");
- }
- });
+ _status.setText("Ready");
}
@Override
@@ -413,14 +409,7 @@ public class Client extends JFrame
{
assert (!_response);
_response = true;
-
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- handleException(ex);
- }
- });
+ handleException(ex);
}
@Override
@@ -431,20 +420,14 @@ public class Client extends JFrame
return;
}
- SwingUtilities.invokeLater(new Runnable()
+ if(_deliveryMode == DeliveryMode.TWOWAY || _deliveryMode == DeliveryMode.TWOWAY_SECURE)
{
- public void run()
- {
- if(_deliveryMode == DeliveryMode.TWOWAY || _deliveryMode == DeliveryMode.TWOWAY_SECURE)
- {
- _status.setText("Waiting for response");
- }
- else
- {
- _status.setText("Ready");
- }
- }
- });
+ _status.setText("Waiting for response");
+ }
+ else
+ {
+ _status.setText("Ready");
+ }
}
private boolean _response = false;
@@ -499,25 +482,13 @@ public class Client extends JFrame
@Override
public void response()
{
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- _status.setText("Ready");
- }
- });
+ _status.setText("Ready");
}
@Override
public void exception(final Ice.LocalException ex)
{
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- handleException(ex);
- }
- });
+ handleException(ex);
}
});
if(_deliveryMode == DeliveryMode.TWOWAY || _deliveryMode == DeliveryMode.TWOWAY_SECURE)
@@ -550,13 +521,7 @@ public class Client extends JFrame
}
catch(final Ice.LocalException ex)
{
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- handleException(ex);
- }
- });
+ handleException(ex);
}
}
}).start();
@@ -605,13 +570,7 @@ public class Client extends JFrame
return;
}
ex.printStackTrace();
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- _status.setText(ex.getClass().getName());
- }
- });
+ _status.setText(ex.getClass().getName());
}
private static class SliderListener implements ChangeListener