diff options
author | Matthew Newhook <matthew@zeroc.com> | 2015-01-13 15:10:13 -0330 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2015-01-13 15:10:13 -0330 |
commit | 035ea969be6dfc4ccd12e5c51c119bb2fe47ffa6 (patch) | |
tree | b8f7c88f6d5874e89e75319f002bf657d1017760 /java/demo/Ice/swing/Client.java | |
parent | ICE-6236 android chat demo: crash (diff) | |
download | ice-035ea969be6dfc4ccd12e5c51c119bb2fe47ffa6.tar.bz2 ice-035ea969be6dfc4ccd12e5c51c119bb2fe47ffa6.tar.xz ice-035ea969be6dfc4ccd12e5c51c119bb2fe47ffa6.zip |
Fix bug with oneway invocations in the android hello demo.
Aligned java GUI demos with the changes to the android demo.
Fixed bug with the applet demo.
Diffstat (limited to 'java/demo/Ice/swing/Client.java')
-rw-r--r-- | java/demo/Ice/swing/Client.java | 157 |
1 files changed, 80 insertions, 77 deletions
diff --git a/java/demo/Ice/swing/Client.java b/java/demo/Ice/swing/Client.java index e84f7c1fe38..f06ade4cf27 100644 --- a/java/demo/Ice/swing/Client.java +++ b/java/demo/Ice/swing/Client.java @@ -145,12 +145,7 @@ public class Client extends JFrame } }); - final String[] modes = new String[] - { - "Twoway", "Twoway Secure", "Oneway", "Oneway Batch", "Oneway Secure", "Oneway Secure Batch", "Datagram", - "Datagram Batch" - }; - _mode.setModel(new DefaultComboBoxModel<String>(modes)); + _mode.setModel(new DefaultComboBoxModel<String>(DELIVERY_MODE_DESC)); _hello.addActionListener(new ActionListener() { @@ -356,6 +351,27 @@ public class Client extends JFrame setVisible(true); } + // These two arrays match and match the order of the delivery mode enumeration. + private final static DeliveryMode DELIVERY_MODES[] = { + DeliveryMode.TWOWAY, + DeliveryMode.TWOWAY_SECURE, + DeliveryMode.ONEWAY, + DeliveryMode.ONEWAY_BATCH, + DeliveryMode.ONEWAY_SECURE, + DeliveryMode.ONEWAY_SECURE_BATCH, + DeliveryMode.DATAGRAM, + DeliveryMode.DATAGRAM_BATCH, + }; + private final static String DELIVERY_MODE_DESC[] = new String[] { + "Twoway", + "Twoway Secure", + "Oneway", + "Oneway Batch", + "Oneway Secure", + "Oneway Secure Batch", + "Datagram", + "Datagram Batch" + }; private enum DeliveryMode { TWOWAY, @@ -415,6 +431,11 @@ public class Client extends JFrame return prx; } + public boolean isOneway() + { + return this == ONEWAY || this == ONEWAY_SECURE; + } + public boolean isBatch() { return this == ONEWAY_BATCH || this == DATAGRAM_BATCH || this == ONEWAY_SECURE_BATCH; @@ -442,45 +463,6 @@ public class Client extends JFrame _status.setText("Ready"); } - class SayHelloI extends Demo.Callback_Hello_sayHello - { - @Override - synchronized public void response() - { - assert (!_response); - _response = true; - _status.setText("Ready"); - } - - @Override - synchronized public void exception(final Ice.LocalException ex) - { - assert (!_response); - _response = true; - handleException(ex); - } - - @Override - synchronized public void sent(boolean ss) - { - if(_response) - { - return; - } - - if(_deliveryMode == DeliveryMode.TWOWAY || _deliveryMode == DeliveryMode.TWOWAY_SECURE) - { - _status.setText("Waiting for response"); - } - else - { - _status.setText("Ready"); - } - } - - private boolean _response = false; - } - private void sayHello() { if(_helloPrx == null) @@ -494,7 +476,39 @@ public class Client extends JFrame if(!_deliveryMode.isBatch()) { _status.setText("Sending request"); - _helloPrx.begin_sayHello(delay, new SayHelloI()); + final DeliveryMode mode = _deliveryMode; + _helloPrx.begin_sayHello(delay, new Demo.Callback_Hello_sayHello() { + @Override + public void response() + { + assert (!_response); + _response = true; + _status.setText("Ready"); + } + + @Override + public void exception(final Ice.LocalException ex) + { + assert (!_response); + _response = true; + handleException(ex); + } + + @Override + public void sent(boolean ss) + { + if(mode.isOneway()) + { + _status.setText("Ready"); + } + else if(!_response) + { + _status.setText("Waiting for response"); + } + } + + private boolean _response = false; + }); } else { @@ -520,24 +534,39 @@ public class Client extends JFrame { if(!_deliveryMode.isBatch()) { + _status.setText("Sending request"); + final DeliveryMode mode = _deliveryMode; _helloPrx.begin_shutdown(new Demo.Callback_Hello_shutdown() { @Override public void response() { + _response = true; _status.setText("Ready"); } @Override public void exception(final Ice.LocalException ex) { + _response = true; handleException(ex); } + + @Override + public void sent(boolean ss) + { + if(mode.isOneway()) + { + _status.setText("Ready"); + } + else if(!_response) + { + _status.setText("Waiting for response"); + } + } + + private boolean _response = false; }); - if(_deliveryMode == DeliveryMode.TWOWAY || _deliveryMode == DeliveryMode.TWOWAY_SECURE) - { - _status.setText("Waiting for response"); - } } else { @@ -569,33 +598,7 @@ public class Client extends JFrame private void changeDeliveryMode(long id) { - switch ((int)id) - { - case 0: - _deliveryMode = DeliveryMode.TWOWAY; - break; - case 1: - _deliveryMode = DeliveryMode.TWOWAY_SECURE; - break; - case 2: - _deliveryMode = DeliveryMode.ONEWAY; - break; - case 3: - _deliveryMode = DeliveryMode.ONEWAY_BATCH; - break; - case 4: - _deliveryMode = DeliveryMode.ONEWAY_SECURE; - break; - case 5: - _deliveryMode = DeliveryMode.ONEWAY_SECURE_BATCH; - break; - case 6: - _deliveryMode = DeliveryMode.DATAGRAM; - break; - case 7: - _deliveryMode = DeliveryMode.DATAGRAM_BATCH; - break; - } + _deliveryMode = DELIVERY_MODES[(int)id]; updateProxy(); } |