summaryrefslogtreecommitdiff
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
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
-rw-r--r--cpp/src/Glacier2Lib/Application.cpp5
-rwxr-xr-xcs/demo/Glacier2/chat/ChatWindow.xaml.cs61
-rw-r--r--cs/demo/Ice/wpf/HelloWindow.xaml.cs51
-rw-r--r--cs/src/Glacier2/Application.cs5
-rw-r--r--cs/src/Glacier2/Makefile7
-rw-r--r--cs/src/Glacier2/SessionCallback.cs3
-rw-r--r--cs/src/Glacier2/SessionHelper.cs97
-rw-r--r--cs/src/Ice/ConnectionI.cs12
-rw-r--r--cs/src/Ice/Dispatcher.cs18
-rw-r--r--cs/src/Ice/Makefile1
-rw-r--r--cs/src/Ice/Makefile.mak1
-rw-r--r--cs/src/Ice/ThreadPool.cs4
-rw-r--r--cs/src/Ice/Util.cs6
-rw-r--r--cs/test/Ice/dispatcher/Client.cs2
-rw-r--r--cs/test/Ice/dispatcher/Dispatcher.cs8
-rw-r--r--cs/test/Ice/dispatcher/Server.cs2
-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
-rw-r--r--java/src/Glacier2/Application.java6
-rw-r--r--java/src/Glacier2/SessionHelper.java55
-rw-r--r--py/python/Glacier2.py6
22 files changed, 285 insertions, 383 deletions
diff --git a/cpp/src/Glacier2Lib/Application.cpp b/cpp/src/Glacier2Lib/Application.cpp
index 92b09e62098..80b6b6ff1e3 100644
--- a/cpp/src/Glacier2Lib/Application.cpp
+++ b/cpp/src/Glacier2Lib/Application.cpp
@@ -143,10 +143,7 @@ Glacier2::Application::objectAdapter()
IceUtil::Mutex::Lock lock(*IceInternal::Application::mutex);
if(!_adapter)
{
- // TODO: Depending on the resolution of
- // http://bugzilla/bugzilla/show_bug.cgi?id=4264 the OA
- // name could be an empty string.
- _adapter = communicator()->createObjectAdapterWithRouter(IceUtil::generateUUID(), router());
+ _adapter = communicator()->createObjectAdapterWithRouter("", router());
_adapter->activate();
}
return _adapter;
diff --git a/cs/demo/Glacier2/chat/ChatWindow.xaml.cs b/cs/demo/Glacier2/chat/ChatWindow.xaml.cs
index ce9dbc9b696..a1eb133ce10 100755
--- a/cs/demo/Glacier2/chat/ChatWindow.xaml.cs
+++ b/cs/demo/Glacier2/chat/ChatWindow.xaml.cs
@@ -68,24 +68,30 @@ namespace Glacier2.chat.client
{
_window = window;
}
+
public override void
message(string data, Ice.Current current)
{
- _window.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)delegate()
- {
- _window.appendMessage(data);
- }
- );
+ _window.appendMessage(data);
}
- ChatWindow _window;
+
+ private ChatWindow _window;
}
public ChatWindow()
{
- Ice.Properties properties = Ice.Util.createProperties();
- properties.load("config.client");
+ Ice.InitializationData initData = new Ice.InitializationData();
+
+ initData.properties = Ice.Util.createProperties();
+ initData.properties.load("config.client");
+
+ // Dispatch servant calls and AMI callbacks with this windows Dispatcher.
+ initData.dispatcher = delegate(System.Action action, Ice.Connection connection)
+ {
+ Dispatcher.BeginInvoke(DispatcherPriority.Normal, action);
+ };
- _factory = new SessionFactoryHelper(properties, this);
+ _factory = new SessionFactoryHelper(initData, this);
InitializeComponent();
Util.locateOnScreen(this);
}
@@ -159,16 +165,10 @@ namespace Glacier2.chat.client
string message = input.Text.Trim();
if(message.Length > 0)
{
- _chat.begin_say(message).whenCompleted(delegate()
- {
- },
- delegate(Ice.Exception ex)
- {
- Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)delegate()
- {
- appendMessage("<system-message> - " + ex.ToString());
- });
- });
+ _chat.begin_say(message).whenCompleted(delegate(Ice.Exception ex)
+ {
+ appendMessage("<system-message> - " + ex.ToString());
+ });
}
input.Text = "";
}
@@ -243,22 +243,16 @@ namespace Glacier2.chat.client
_chat = Demo.ChatSessionPrxHelper.uncheckedCast(_session.session());
_chat.begin_setCallback(callback).whenCompleted(delegate()
{
- Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)delegate()
- {
- closeCancelDialog();
- input.IsEnabled = true;
- status.Content = "Connected with " + _loginData.routerHost;
- });
+ closeCancelDialog();
+ input.IsEnabled = true;
+ status.Content = "Connected with " + _loginData.routerHost;
},
delegate(Ice.Exception ex)
{
- Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)delegate()
+ if(_session != null)
{
- if(_session != null)
- {
- _session.destroy();
- }
- });
+ _session.destroy();
+ }
});
}
@@ -281,11 +275,6 @@ namespace Glacier2.chat.client
status.Content = "Not connected";
}
- public Dispatcher getDispatcher()
- {
- return this.Dispatcher;// System.Windows.Application.Current.Dispatcher;
- }
-
#endregion
}
}
diff --git a/cs/demo/Ice/wpf/HelloWindow.xaml.cs b/cs/demo/Ice/wpf/HelloWindow.xaml.cs
index 5a79a9dfb5a..c48a1d94eb6 100644
--- a/cs/demo/Ice/wpf/HelloWindow.xaml.cs
+++ b/cs/demo/Ice/wpf/HelloWindow.xaml.cs
@@ -52,6 +52,10 @@ namespace Ice.wpf.client
Ice.InitializationData initData = new Ice.InitializationData();
initData.properties = Ice.Util.createProperties();
initData.properties.load("config.client");
+ initData.dispatcher = delegate(System.Action action, Ice.Connection connection)
+ {
+ Dispatcher.BeginInvoke(DispatcherPriority.Normal, action);
+ };
_communicator = Ice.Util.initialize(initData);
}
catch(Ice.LocalException ex)
@@ -129,10 +133,7 @@ namespace Ice.wpf.client
{
Debug.Assert(!_response);
_response = true;
- _window.Dispatcher.BeginInvoke(DispatcherPriority.Normal,(Action)delegate()
- {
- _window.status.Content = "Ready";
- });
+ _window.status.Content = "Ready";
}
}
@@ -142,10 +143,7 @@ namespace Ice.wpf.client
{
Debug.Assert(!_response);
_response = true;
- _window.Dispatcher.BeginInvoke(DispatcherPriority.Normal,(Action)delegate()
- {
- _window.handleException(ex);
- });
+ _window.handleException(ex);
}
}
@@ -157,17 +155,14 @@ namespace Ice.wpf.client
{
return;
}
- _window.Dispatcher.BeginInvoke(DispatcherPriority.Normal,(Action)delegate()
+ if(_window.deliveryMode.Text.Equals(TWOWAY) || _window.deliveryMode.Text.Equals(TWOWAY_SECURE))
{
- if(_window.deliveryMode.Text.Equals(TWOWAY) || _window.deliveryMode.Text.Equals(TWOWAY_SECURE))
- {
- _window.status.Content = "Waiting for response";
- }
- else
- {
- _window.status.Content = "Ready";
- }
- });
+ _window.status.Content = "Waiting for response";
+ }
+ else
+ {
+ _window.status.Content = "Ready";
+ }
}
}
@@ -208,10 +203,7 @@ namespace Ice.wpf.client
private void handleException(Exception ex)
{
- this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,(Action)delegate()
- {
- status.Content = ex.GetType();
- });
+ status.Content = ex.GetType();
}
private void shutdown_Click(object sender, RoutedEventArgs e)
@@ -232,17 +224,11 @@ namespace Ice.wpf.client
status.Content = "Sending request";
result.whenCompleted(delegate()
{
- Dispatcher.BeginInvoke(DispatcherPriority.Normal,(Action)delegate()
- {
- status.Content = "Ready";
- });
+ status.Content = "Ready";
},
delegate(Exception ex)
{
- Dispatcher.BeginInvoke(DispatcherPriority.Normal,(Action)delegate()
- {
- handleException(ex);
- });
+ handleException(ex);
});
}
else
@@ -268,10 +254,7 @@ namespace Ice.wpf.client
}
catch(Ice.LocalException ex)
{
- this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,(Action)delegate()
- {
- handleException(ex);
- });
+ handleException(ex);
}
})).Start();
flush.IsEnabled = false;
diff --git a/cs/src/Glacier2/Application.cs b/cs/src/Glacier2/Application.cs
index 1f1b65c7db9..90e1bed271e 100644
--- a/cs/src/Glacier2/Application.cs
+++ b/cs/src/Glacier2/Application.cs
@@ -191,10 +191,7 @@ public abstract class Application : Ice.Application
{
throw new SessionNotExistException();
}
- // TODO: Depending on the resolution of
- // http://bugzilla/bugzilla/show_bug.cgi?id=4264 the OA
- // name could be an empty string.
- _adapter = communicator().createObjectAdapterWithRouter(Guid.NewGuid().ToString(), _router);
+ _adapter = communicator().createObjectAdapterWithRouter("", _router);
_adapter.activate();
}
return _adapter;
diff --git a/cs/src/Glacier2/Makefile b/cs/src/Glacier2/Makefile
index 80ecba891f0..8c71544d983 100644
--- a/cs/src/Glacier2/Makefile
+++ b/cs/src/Glacier2/Makefile
@@ -14,8 +14,11 @@ LIBNAME = $(PKG).dll
TARGETS = $(bindir)/$(LIBNAME)
POLICY_TARGET = $(POLICY).dll
-SRCS = AssemblyInfo.cs \
- Application.cs
+SRCS = SessionFactoryHelper.cs \
+ SessionHelper.cs \
+ SessionCallback.cs \
+ AssemblyInfo.cs \
+ Application.cs
SLICE_SRCS = $(SDIR)/PermissionsVerifier.ice \
$(SDIR)/Router.ice \
diff --git a/cs/src/Glacier2/SessionCallback.cs b/cs/src/Glacier2/SessionCallback.cs
index 70cbda9126c..61f1edb0192 100644
--- a/cs/src/Glacier2/SessionCallback.cs
+++ b/cs/src/Glacier2/SessionCallback.cs
@@ -50,9 +50,6 @@ public interface SessionCallback
/// <param name="ex">The exception.</param>
void
connectFailed(SessionHelper session, Exception ex);
-
- System.Windows.Threading.Dispatcher
- getDispatcher();
}
}
diff --git a/cs/src/Glacier2/SessionHelper.cs b/cs/src/Glacier2/SessionHelper.cs
index a8f37468e1e..d3f11269b8b 100644
--- a/cs/src/Glacier2/SessionHelper.cs
+++ b/cs/src/Glacier2/SessionHelper.cs
@@ -10,7 +10,6 @@
using System;
using System.Diagnostics;
using System.Threading;
-using System.Windows.Threading;
namespace Glacier2
{
@@ -264,10 +263,7 @@ public class SessionHelper
}
if(_adapter == null)
{
- // TODO: Depending on the resolution of
- // http://bugzilla/bugzilla/show_bug.cgi?id=4264 the OA
- // name could be an empty string.
- _adapter = _communicator.createObjectAdapterWithRouter(Guid.NewGuid().ToString(), _router);
+ _adapter = _communicator.createObjectAdapterWithRouter("", _router);
_adapter.activate();
}
return _adapter;
@@ -336,18 +332,17 @@ public class SessionHelper
_refreshThread.Start();
- _callback.getDispatcher().Invoke(DispatcherPriority.Normal,
- (Action)delegate()
- {
- try
- {
- _callback.connected(this);
- }
- catch(Glacier2.SessionNotExistException)
- {
- destroy();
- }
- });
+ dispatchCallback(delegate()
+ {
+ try
+ {
+ _callback.connected(this);
+ }
+ catch(Glacier2.SessionNotExistException)
+ {
+ destroy();
+ }
+ });
}
}
@@ -406,11 +401,10 @@ public class SessionHelper
_communicator = null;
// Notify the callback that the session is gone.
- _callback.getDispatcher().BeginInvoke(DispatcherPriority.Normal,
- (Action)delegate()
- {
- _callback.disconnected(this);
- });
+ dispatchCallback(delegate()
+ {
+ _callback.disconnected(this);
+ });
}
}
@@ -429,10 +423,10 @@ public class SessionHelper
catch(Ice.LocalException ex)
{
_destroy = true;
- _callback.getDispatcher().BeginInvoke(DispatcherPriority.Normal, (Action)delegate()
- {
- _callback.connectFailed(this, ex);
- });
+ dispatchCallback(delegate()
+ {
+ _callback.connectFailed(this, ex);
+ });
return;
}
@@ -440,14 +434,13 @@ public class SessionHelper
{
try
{
- _callback.getDispatcher().BeginInvoke(DispatcherPriority.Normal,
- (Action)delegate()
- {
- _callback.createdCommunicator(this);
- });
+ dispatchCallbackAndWait(delegate()
+ {
+ _callback.createdCommunicator(this);
+ });
Glacier2.RouterPrx routerPrx = Glacier2.RouterPrxHelper.uncheckedCast(
- _communicator.getDefaultRouter());
+ _communicator.getDefaultRouter());
Glacier2.SessionPrx session = factory(routerPrx);
connected(routerPrx, session);
}
@@ -461,14 +454,46 @@ public class SessionHelper
{
}
- _callback.getDispatcher().BeginInvoke(DispatcherPriority.Normal, (Action)delegate()
- {
- _callback.connectFailed(this, ex);
- });
+ dispatchCallback(delegate()
+ {
+ _callback.connectFailed(this, ex);
+ });
}
})).Start();
}
+ private void
+ dispatchCallback(System.Action callback)
+ {
+ if(_initData.dispatcher != null)
+ {
+ _initData.dispatcher(callback, null);
+ }
+ else
+ {
+ callback();
+ }
+ }
+
+ private void
+ dispatchCallbackAndWait(System.Action callback)
+ {
+ if(_initData.dispatcher != null)
+ {
+ EventWaitHandle h = new EventWaitHandle(false, EventResetMode.ManualReset);
+ _initData.dispatcher(delegate()
+ {
+ callback();
+ h.Set();
+ }, null);
+ h.WaitOne();
+ }
+ else
+ {
+ callback();
+ }
+ }
+
private Ice.InitializationData _initData;
private Ice.Communicator _communicator;
private Ice.ObjectAdapter _adapter;
diff --git a/cs/src/Ice/ConnectionI.cs b/cs/src/Ice/ConnectionI.cs
index bb3329037d9..b24cea35a67 100644
--- a/cs/src/Ice/ConnectionI.cs
+++ b/cs/src/Ice/ConnectionI.cs
@@ -1187,11 +1187,11 @@ namespace Ice
{
try
{
- _dispatcher.dispatch(delegate()
- {
- dispatch(startCB, sentCBs, info);
- },
- this);
+ _dispatcher(delegate()
+ {
+ dispatch(startCB, sentCBs, info);
+ },
+ this);
}
catch(System.Exception ex)
{
@@ -1286,7 +1286,7 @@ namespace Ice
{
try
{
- _dispatcher.dispatch(delegate() { finish(); }, this);
+ _dispatcher(finish, this);
}
catch(System.Exception ex)
{
diff --git a/cs/src/Ice/Dispatcher.cs b/cs/src/Ice/Dispatcher.cs
deleted file mode 100644
index 245384dd1a4..00000000000
--- a/cs/src/Ice/Dispatcher.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-
-namespace Ice
-{
- public delegate void DispatcherCall();
-
- public interface Dispatcher
- {
- void dispatch(DispatcherCall call, Ice.Connection con);
- }
-} \ No newline at end of file
diff --git a/cs/src/Ice/Makefile b/cs/src/Ice/Makefile
index d90b958a212..75c648e7b66 100644
--- a/cs/src/Ice/Makefile
+++ b/cs/src/Ice/Makefile
@@ -25,7 +25,6 @@ SRCS = Acceptor.cs \
BasicStream.cs \
Buffer.cs \
ByteBuffer.cs \
- Dispatcher.cs \
CommunicatorI.cs \
Compare.cs \
CollectionBase.cs \
diff --git a/cs/src/Ice/Makefile.mak b/cs/src/Ice/Makefile.mak
index 07308e2a59a..34d8d02a5a3 100644
--- a/cs/src/Ice/Makefile.mak
+++ b/cs/src/Ice/Makefile.mak
@@ -25,7 +25,6 @@ SRCS = Acceptor.cs \
BasicStream.cs \
Buffer.cs \
ByteBuffer.cs \
- Dispatcher.cs \
CommunicatorI.cs \
Compare.cs \
CollectionBase.cs \
diff --git a/cs/src/Ice/ThreadPool.cs b/cs/src/Ice/ThreadPool.cs
index 868338639fa..c39c105f0f3 100644
--- a/cs/src/Ice/ThreadPool.cs
+++ b/cs/src/Ice/ThreadPool.cs
@@ -313,13 +313,13 @@ namespace IceInternal
}
public void
- dispatch(Ice.DispatcherCall call)
+ dispatch(System.Action call)
{
if(_dispatcher != null)
{
try
{
- _dispatcher.dispatch(call, null);
+ _dispatcher(call, null);
}
catch(System.Exception ex)
{
diff --git a/cs/src/Ice/Util.cs b/cs/src/Ice/Util.cs
index 31b3fc44323..7b5b6fa13e9 100644
--- a/cs/src/Ice/Util.cs
+++ b/cs/src/Ice/Util.cs
@@ -35,6 +35,12 @@ namespace Ice
}
/// <summary>
+ /// A delegate for the dispatcher. The dispatcher is called by the Ice
+ /// runtime to dispatch servant calls and AMI callbacks.
+ /// </summary>
+ public delegate void Dispatcher(System.Action call, Connection con);
+
+ /// <summary>
/// A class that encpasulates data to initalize a communicator.
/// </summary>
public class InitializationData : ICloneable
diff --git a/cs/test/Ice/dispatcher/Client.cs b/cs/test/Ice/dispatcher/Client.cs
index 1732942d63b..5700f0a954f 100644
--- a/cs/test/Ice/dispatcher/Client.cs
+++ b/cs/test/Ice/dispatcher/Client.cs
@@ -37,7 +37,7 @@ public class Client
Ice.InitializationData initData = new Ice.InitializationData();
initData.properties = Ice.Util.createProperties(ref args);
initData.properties.setProperty("Ice.Warn.AMICallback", "0");
- initData.dispatcher = new Dispatcher();
+ initData.dispatcher = new Dispatcher().dispatch;
communicator = Ice.Util.initialize(ref args, initData);
status = run(args, communicator);
}
diff --git a/cs/test/Ice/dispatcher/Dispatcher.cs b/cs/test/Ice/dispatcher/Dispatcher.cs
index 035d21b4a90..044a3c2283f 100644
--- a/cs/test/Ice/dispatcher/Dispatcher.cs
+++ b/cs/test/Ice/dispatcher/Dispatcher.cs
@@ -13,7 +13,7 @@ using System.Reflection;
using System.Collections.Generic;
using System.Threading;
-public class Dispatcher : Ice.Dispatcher
+public class Dispatcher
{
private static void test(bool b)
{
@@ -36,7 +36,7 @@ public class Dispatcher : Ice.Dispatcher
{
while(true)
{
- Ice.DispatcherCall call = null;
+ System.Action call = null;
lock(this)
{
if(!_terminated && _calls.Count == 0)
@@ -71,7 +71,7 @@ public class Dispatcher : Ice.Dispatcher
}
public void
- dispatch(Ice.DispatcherCall call, Ice.Connection con)
+ dispatch(System.Action call, Ice.Connection con)
{
lock(this)
{
@@ -103,7 +103,7 @@ public class Dispatcher : Ice.Dispatcher
static Dispatcher _instance;
- private Queue<Ice.DispatcherCall> _calls = new Queue<Ice.DispatcherCall>();
+ private Queue<System.Action> _calls = new Queue<System.Action>();
Thread _thread;
bool _terminated = false;
};
diff --git a/cs/test/Ice/dispatcher/Server.cs b/cs/test/Ice/dispatcher/Server.cs
index f3be06d1419..12419e8701e 100644
--- a/cs/test/Ice/dispatcher/Server.cs
+++ b/cs/test/Ice/dispatcher/Server.cs
@@ -49,7 +49,7 @@ public class Server
Ice.InitializationData initData = new Ice.InitializationData();
initData.properties = Ice.Util.createProperties(ref args);
initData.properties.setProperty("Ice.ServerIdleTime", "30");
- initData.dispatcher = new Dispatcher();
+ initData.dispatcher = new Dispatcher().dispatch;
communicator = Ice.Util.initialize(ref args, initData);
status = run(args, communicator);
}
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
diff --git a/java/src/Glacier2/Application.java b/java/src/Glacier2/Application.java
index 488c3f22f19..d005e32c8b3 100644
--- a/java/src/Glacier2/Application.java
+++ b/java/src/Glacier2/Application.java
@@ -216,11 +216,7 @@ public abstract class Application extends Ice.Application
{
throw new SessionNotExistException();
}
- // TODO: Depending on the resolution of
- // http://bugzilla/bugzilla/show_bug.cgi?id=4264 the OA
- // name could be an empty string.
- String uuid = java.util.UUID.randomUUID().toString();
- _adapter = communicator().createObjectAdapterWithRouter(uuid, _router);
+ _adapter = communicator().createObjectAdapterWithRouter("", _router);
_adapter.activate();
}
return _adapter;
diff --git a/java/src/Glacier2/SessionHelper.java b/java/src/Glacier2/SessionHelper.java
index dbb91db401c..3656a62835d 100644
--- a/java/src/Glacier2/SessionHelper.java
+++ b/java/src/Glacier2/SessionHelper.java
@@ -6,9 +6,8 @@
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
-package Glacier2;
-import javax.swing.SwingUtilities;
+package Glacier2;
/**
* A helper class for using Glacier2 with GUI applications.
@@ -240,10 +239,7 @@ public class SessionHelper
}
if(_adapter == null)
{
- // TODO: Depending on the resolution of
- // http://bugzilla/bugzilla/show_bug.cgi?id=4264 the OA
- // name could be an empty string.
- _adapter = _communicator.createObjectAdapterWithRouter(java.util.UUID.randomUUID().toString(), _router);
+ _adapter = _communicator.createObjectAdapterWithRouter("", _router);
_adapter.activate();
}
return _adapter;
@@ -340,7 +336,7 @@ public class SessionHelper
// hooks.
}
- SwingUtilities.invokeLater(new Runnable()
+ dispatchCallback(new Runnable()
{
public void run()
{
@@ -408,7 +404,7 @@ public class SessionHelper
_communicator = null;
// Notify the callback that the session is gone.
- SwingUtilities.invokeLater(new Runnable()
+ dispatchCallback(new Runnable()
{
public void run()
{
@@ -429,7 +425,7 @@ public class SessionHelper
catch(final Ice.LocalException ex)
{
_destroy = true;
- SwingUtilities.invokeLater(new Runnable()
+ dispatchCallback(new Runnable()
{
public void run()
{
@@ -445,7 +441,7 @@ public class SessionHelper
{
try
{
- SwingUtilities.invokeAndWait(new Runnable()
+ dispatchCallbackAndWait(new Runnable()
{
public void run()
{
@@ -468,7 +464,7 @@ public class SessionHelper
{
}
- SwingUtilities.invokeLater(new Runnable()
+ dispatchCallback(new Runnable()
{
public void run()
{
@@ -480,6 +476,43 @@ public class SessionHelper
}).start();
}
+ private void
+ dispatchCallback(Runnable runnable)
+ {
+ if(_initData.dispatcher != null)
+ {
+ _initData.dispatcher.dispatch(runnable, null);
+ }
+ else
+ {
+ runnable.run();
+ }
+ }
+
+ private void
+ dispatchCallbackAndWait(final Runnable runnable)
+ {
+ if(_initData.dispatcher != null)
+ {
+ final java.util.concurrent.Semaphore sem = new java.util.concurrent.Semaphore(0);
+ _initData.dispatcher.dispatch(
+ new Runnable()
+ {
+ public void
+ run()
+ {
+ runnable.run();
+ sem.release();
+ }
+ }, null);
+ sem.acquireUninterruptibly();
+ }
+ else
+ {
+ runnable.run();
+ }
+ }
+
private Ice.InitializationData _initData;
private Ice.Communicator _communicator;
private Ice.ObjectAdapter _adapter;
diff --git a/py/python/Glacier2.py b/py/python/Glacier2.py
index c1238e99025..da42d6d2981 100644
--- a/py/python/Glacier2.py
+++ b/py/python/Glacier2.py
@@ -133,11 +133,7 @@ Application.NoSignalHandling.
if Application._adapter == None:
if Application._router == None:
raise SessionNotExistException()
- # TODO: Depending on the resolution of
- # http://bugzilla/bugzilla/show_bug.cgi?id=4264 the OA
- # name could be an empty string.
- uuid = Ice.generateUUID()
- Application._adapter = self.communicator().createObjectAdapterWithRouter(uuid, Application._router)
+ Application._adapter = self.communicator().createObjectAdapterWithRouter("", Application._router)
Application._adapter.activate()
return Application._adapter