summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2017-01-30 13:45:21 -0800
committerMark Spruiell <mes@zeroc.com>2017-01-30 13:45:21 -0800
commit61270a10f980933cf582edb766f10c8ac6d86e8a (patch)
tree45ab4a7c2986954054fce613bc3c8f7967e7951e /js
parentFix slice2cpp build failure (diff)
downloadice-61270a10f980933cf582edb766f10c8ac6d86e8a.tar.bz2
ice-61270a10f980933cf582edb766f10c8ac6d86e8a.tar.xz
ice-61270a10f980933cf582edb766f10c8ac6d86e8a.zip
merging IceBridge into master
Diffstat (limited to 'js')
-rw-r--r--js/src/Ice/ConnectionI.js50
-rw-r--r--js/src/Ice/OutgoingAsync.js33
-rw-r--r--js/test/Ice/acm/Client.js34
-rw-r--r--js/test/Ice/acm/Test.ice3
-rw-r--r--js/test/Ice/ami/Client.js8
-rw-r--r--js/test/Ice/binding/Client.js12
-rw-r--r--js/test/Ice/hold/Client.js2
-rw-r--r--js/test/Ice/location/Client.js2
-rw-r--r--js/test/Ice/operations/BatchOneways.js2
-rw-r--r--js/test/Ice/timeout/Client.js4
10 files changed, 113 insertions, 37 deletions
diff --git a/js/src/Ice/ConnectionI.js b/js/src/Ice/ConnectionI.js
index c56e764a01e..4541098ae78 100644
--- a/js/src/Ice/ConnectionI.js
+++ b/js/src/Ice/ConnectionI.js
@@ -35,6 +35,7 @@ const InputStream = Ice.InputStream;
const OutputStream = Ice.OutputStream;
const BatchRequestQueue = Ice.BatchRequestQueue;
const ConnectionFlushBatch = Ice.ConnectionFlushBatch;
+const HeartbeatAsync = Ice.HeartbeatAsync;
const Debug = Ice.Debug;
const ExUtil = Ice.ExUtil;
const HashMap = Ice.HashMap;
@@ -49,6 +50,7 @@ const EncodingVersion = Ice.EncodingVersion;
const ACM = Ice.ACM;
const ACMClose = Ice.ACMClose;
const ACMHeartbeat = Ice.ACMHeartbeat;
+const ConnectionClose = Ice.ConnectionClose;
const StateNotInitialized = 0;
const StateNotValidated = 1;
@@ -218,23 +220,26 @@ class ConnectionI
}
}
- close(force)
+ close(mode)
{
const r = new AsyncResultBase(this._communicator, "close", this, null, null);
- if(force)
+ if(mode == ConnectionClose.CloseForcefully)
{
- this.setState(StateClosed, new Ice.ForcedCloseConnectionException());
+ this.setState(StateClosed, new Ice.ConnectionManuallyClosedException(false));
+ r.resolve();
+ }
+ else if(mode == ConnectionClose.CloseGracefully)
+ {
+ this.setState(StateClosing, new Ice.ConnectionManuallyClosedException(true));
r.resolve();
}
else
{
+ Debug.assert(mode == ConnectionClose.CloseGracefullyAndWait);
+
//
- // If we do a graceful shutdown, then we wait until all
- // outstanding requests have been completed. Otherwise,
- // the CloseConnectionException will cause all outstanding
- // requests to be retried, regardless of whether the
- // server has processed them or not.
+ // Wait until all outstanding requests have been completed.
//
this._closePromises.push(r);
this.checkClose();
@@ -246,13 +251,13 @@ class ConnectionI
checkClose()
{
//
- // If close(false) has been called, then we need to check if all
+ // If close(CloseGracefullyAndWait) has been called, then we need to check if all
// requests have completed and we can transition to StateClosing.
// We also complete outstanding promises.
//
if(this._asyncRequests.size === 0 && this._closePromises.length > 0)
{
- this.setState(StateClosing, new Ice.CloseConnectionException());
+ this.setState(StateClosing, new Ice.ConnectionManuallyClosedException(true));
this._closePromises.forEach(p => p.resolve());
this._closePromises = [];
}
@@ -310,13 +315,13 @@ class ConnectionI
// We send a heartbeat if there was no activity in the last
// (timeout / 4) period. Sending a heartbeat sooner than
// really needed is safer to ensure that the receiver will
- // receive in time the heartbeat. Sending the heartbeat if
+ // receive the heartbeat in time. Sending the heartbeat if
// there was no activity in the last (timeout / 2) period
// isn't enough since monitor() is called only every (timeout
// / 2) period.
//
// Note that this doesn't imply that we are sending 4 heartbeats
- // per timeout period because the monitor() method is sill only
+ // per timeout period because the monitor() method is still only
// called every (timeout / 2) period.
//
if(acm.heartbeat == Ice.ACMHeartbeat.HeartbeatAlways ||
@@ -325,7 +330,7 @@ class ConnectionI
{
if(acm.heartbeat != Ice.ACMHeartbeat.HeartbeatOnInvocation || this._dispatchCount > 0)
{
- this.heartbeat(); // Send heartbeat if idle in the last timeout / 2 period.
+ this.sendHeartbeatNow(); // Send heartbeat if idle in the last timeout / 2 period.
}
}
@@ -488,6 +493,13 @@ class ConnectionI
this._heartbeatCallback = callback;
}
+ heartbeat()
+ {
+ const result = new HeartbeatAsync(this, this._communicator);
+ result.invoke();
+ return result;
+ }
+
setACM(timeout, close, heartbeat)
{
if(this._monitor === null || this._state >= StateClosed)
@@ -1008,7 +1020,7 @@ class ConnectionI
// Trace the cause of unexpected connection closures
//
if(!(this._exception instanceof Ice.CloseConnectionException ||
- this._exception instanceof Ice.ForcedCloseConnectionException ||
+ this._exception instanceof Ice.ConnectionManuallyClosedException ||
this._exception instanceof Ice.ConnectionTimeoutException ||
this._exception instanceof Ice.CommunicatorDestroyedException ||
this._exception instanceof Ice.ObjectAdapterDeactivatedException))
@@ -1211,7 +1223,7 @@ class ConnectionI
// Don't warn about certain expected exceptions.
//
if(!(this._exception instanceof Ice.CloseConnectionException ||
- this._exception instanceof Ice.ForcedCloseConnectionException ||
+ this._exception instanceof Ice.ConnectionManuallyClosedException ||
this._exception instanceof Ice.ConnectionTimeoutException ||
this._exception instanceof Ice.CommunicatorDestroyedException ||
this._exception instanceof Ice.ObjectAdapterDeactivatedException ||
@@ -1416,15 +1428,13 @@ class ConnectionI
initiateShutdown()
{
- Debug.assert(this._state === StateClosing);
- Debug.assert(this._dispatchCount === 0);
+ Debug.assert(this._state === StateClosing && this._dispatchCount === 0);
Debug.assert(!this._shutdownInitiated);
if(!this._endpoint.datagram())
{
//
- // Before we shut down, we send a close connection
- // message.
+ // Before we shut down, we send a close connection message.
//
const os = new OutputStream(this._instance, Protocol.currentProtocolEncoding);
os.writeBlob(Protocol.magic);
@@ -1454,7 +1464,7 @@ class ConnectionI
}
}
- heartbeat()
+ sendHeartbeatNow()
{
Debug.assert(this._state === StateActive);
diff --git a/js/src/Ice/OutgoingAsync.js b/js/src/Ice/OutgoingAsync.js
index 62f14f0f64a..bce53bc29a9 100644
--- a/js/src/Ice/OutgoingAsync.js
+++ b/js/src/Ice/OutgoingAsync.js
@@ -578,9 +578,42 @@ class ConnectionFlushBatch extends OutgoingAsyncBase
}
}
+class HeartbeatAsync extends OutgoingAsyncBase
+{
+ constructor(con, communicator)
+ {
+ super(communicator, "heartbeat", con, null, null);
+ }
+
+ invoke()
+ {
+ try
+ {
+ this._os.writeBlob(Protocol.magic);
+ Protocol.currentProtocol._write(this._os);
+ Protocol.currentProtocolEncoding._write(this._os);
+ this._os.writeByte(Protocol.validateConnectionMsg);
+ this._os.writeByte(0);
+ this._os.writeInt(Protocol.headerSize); // Message size.
+
+ let status = this._connection.sendAsyncRequest(this, false, false, 0);
+
+ if((status & AsyncStatus.Sent) > 0)
+ {
+ this._sentSynchronously = true;
+ }
+ }
+ catch(ex)
+ {
+ this.completedEx(ex);
+ }
+ }
+}
+
Ice.OutgoingAsync = OutgoingAsync;
Ice.ProxyFlushBatch = ProxyFlushBatch;
Ice.ProxyGetConnection = ProxyGetConnection;
Ice.ConnectionFlushBatch = ConnectionFlushBatch;
+Ice.HeartbeatAsync = HeartbeatAsync;
module.exports.Ice = Ice;
diff --git a/js/test/Ice/acm/Client.js b/js/test/Ice/acm/Client.js
index e18f45ec0ac..58f8efdf313 100644
--- a/js/test/Ice/acm/Client.js
+++ b/js/test/Ice/acm/Client.js
@@ -391,6 +391,37 @@
}
}
+ class HeartbeatManualTest extends TestCase
+ {
+ constructor(com, out)
+ {
+ super("manual heartbeats", com, out);
+ //
+ // Disable heartbeats.
+ //
+ this.setClientACM(10, -1, 0);
+ this.setServerACM(10, -1, 0);
+ }
+
+ runTestCase(adapter, proxy)
+ {
+ function sendHeartbeats(con)
+ {
+ var p = Promise.resolve();
+ for(var i = 0; i < 5; ++i)
+ {
+ p = p.then(con.heartbeat());
+ }
+ return p;
+ }
+
+ return proxy.startHeartbeatCount().then(
+ () => proxy.ice_getConnection()).then(
+ con => sendHeartbeats(con)).then(
+ () => proxy.waitForHeartbeatCount(5));
+ }
+ }
+
class SetACMTest extends TestCase
{
constructor(com, out)
@@ -421,7 +452,7 @@
test(acm.close === Ice.ACMClose.CloseOnInvocationAndIdle);
test(acm.heartbeat === Ice.ACMHeartbeat.HeartbeatAlways);
- return proxy.waitForHeartbeat(2);
+ return proxy.startHeartbeatCount().then(() => proxy.waitForHeartbeatCount(2));
}
}
@@ -459,6 +490,7 @@
tests.push(new HeartbeatOnIdleTest(com, out));
tests.push(new HeartbeatAlwaysTest(com, out));
+ tests.push(new HeartbeatManualTest(com, out));
tests.push(new SetACMTest(com, out));
}
diff --git a/js/test/Ice/acm/Test.ice b/js/test/Ice/acm/Test.ice
index 117192a2df8..7f71427c741 100644
--- a/js/test/Ice/acm/Test.ice
+++ b/js/test/Ice/acm/Test.ice
@@ -18,7 +18,8 @@ interface TestIntf
void sleep(int seconds);
void sleepAndHold(int seconds);
void interruptSleep();
- void waitForHeartbeat(int count);
+ void startHeartbeatCount();
+ void waitForHeartbeatCount(int count);
};
interface RemoteObjectAdapter
diff --git a/js/test/Ice/ami/Client.js b/js/test/Ice/ami/Client.js
index 07b9ae03db4..39b5aeae704 100644
--- a/js/test/Ice/ami/Client.js
+++ b/js/test/Ice/ami/Client.js
@@ -111,7 +111,7 @@
//
test(batchCount === 0);
b1.opBatch();
- b1.ice_getCachedConnection().close(false);
+ b1.ice_getCachedConnection().close(Ice.ConnectionClose.CloseGracefullyAndWait);
return communicator.flushBatchRequests().then(() => p.opBatchCount());
}
).then(batchCount =>
@@ -156,7 +156,7 @@
b2 = prx;
b1.opBatch();
b2.opBatch();
- b1.ice_getCachedConnection().close(false);
+ b1.ice_getCachedConnection().close(Ice.ConnectionClose.CloseGracefullyAndWait);
return communicator.flushBatchRequests();
}
).then(() => p.waitForBatch(1)
@@ -181,8 +181,8 @@
b2 = prx;
b1.opBatch();
b2.opBatch();
- b1.ice_getCachedConnection().close(false);
- b2.ice_getCachedConnection().close(false);
+ b1.ice_getCachedConnection().close(Ice.ConnectionClose.CloseGracefullyAndWait);
+ b2.ice_getCachedConnection().close(Ice.ConnectionClose.CloseGracefullyAndWait);
return communicator.flushBatchRequests();
}
).then(() => p.opBatchCount());
diff --git a/js/test/Ice/binding/Client.js b/js/test/Ice/binding/Client.js
index ecba375108b..0e59e8256c7 100644
--- a/js/test/Ice/binding/Client.js
+++ b/js/test/Ice/binding/Client.js
@@ -260,7 +260,7 @@
).then(
function(conn)
{
- return conn.close(false);
+ return conn.close(Ice.ConnectionClose.CloseGracefullyAndWait);
}
).then(
function()
@@ -339,7 +339,7 @@
}).then(
function(c)
{
- return c.close(false);
+ return c.close(Ice.ConnectionClose.CloseGracefullyAndWait);
}
);
}));
@@ -422,7 +422,7 @@
).then(
function(conn)
{
- return conn.close(false);
+ return conn.close(Ice.ConnectionClose.CloseGracefullyAndWait);
}
).then(
function()
@@ -585,7 +585,7 @@
}).then(
function(c)
{
- return c.close(false);
+ return c.close(Ice.ConnectionClose.CloseGracefullyAndWait);
},
function(ex)
{
@@ -651,7 +651,7 @@
}
return prx.ice_getConnection();
}
- ).then(conn => conn.close(false)
+ ).then(conn => conn.close(Ice.ConnectionClose.CloseGracefullyAndWait)
).then(() => names.length > 0 ? f1() : prx);
};
@@ -678,7 +678,7 @@
).then(
function(conn)
{
- return conn.close(false);
+ return conn.close(Ice.ConnectionClose.CloseGracefullyAndWait);
}
).then(
function()
diff --git a/js/test/Ice/hold/Client.js b/js/test/Ice/hold/Client.js
index 51e3bf70c12..03f31d4c353 100644
--- a/js/test/Ice/hold/Client.js
+++ b/js/test/Ice/hold/Client.js
@@ -230,7 +230,7 @@
).then(
function(con)
{
- return con.close(false);
+ return con.close(Ice.ConnectionClose.CloseGracefullyAndWait);
}
);
}
diff --git a/js/test/Ice/location/Client.js b/js/test/Ice/location/Client.js
index 5890344ed19..62168831822 100644
--- a/js/test/Ice/location/Client.js
+++ b/js/test/Ice/location/Client.js
@@ -1110,7 +1110,7 @@
).then(
function(con)
{
- return con.close(false);
+ return con.close(Ice.ConnectionClose.CloseGracefullyAndWait);
}
).then(
function()
diff --git a/js/test/Ice/operations/BatchOneways.js b/js/test/Ice/operations/BatchOneways.js
index d3a66fa51c1..b6660b97781 100644
--- a/js/test/Ice/operations/BatchOneways.js
+++ b/js/test/Ice/operations/BatchOneways.js
@@ -82,7 +82,7 @@
).then(count => batch.ice_flushBatchRequests()
).then(() => prx.opByteSOnewayCallCount()
).then(() => batch.ice_getConnection()
- ).then(con => bidir ? undefined : con.close(false)
+ ).then(con => bidir ? undefined : con.close(Ice.ConnectionClose.CloseGracefullyAndWait)
).then(() => Promise.all([batch.ice_ping(), batch2.ice_ping()])
).then(() =>
{
diff --git a/js/test/Ice/timeout/Client.js b/js/test/Ice/timeout/Client.js
index 62790d63f54..9f2872dfecb 100644
--- a/js/test/Ice/timeout/Client.js
+++ b/js/test/Ice/timeout/Client.js
@@ -142,7 +142,7 @@
connection = con;
return timeout.holdAdapter(1500);
}
- ).then(() => connection.close(false)
+ ).then(() => connection.close(Ice.ConnectionClose.CloseGracefullyAndWait)
).then(() =>
{
try
@@ -163,7 +163,7 @@
}
catch(ex)
{
- test(ex instanceof Ice.CloseConnectionException); // Expected
+ test(ex instanceof Ice.ConnectionManuallyClosedException); // Expected
}
return timeout.op();
}