本文整理汇总了Java中org.voltdb.exceptions.SerializableException.serializeToBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java SerializableException.serializeToBuffer方法的具体用法?Java SerializableException.serializeToBuffer怎么用?Java SerializableException.serializeToBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.voltdb.exceptions.SerializableException
的用法示例。
在下文中一共展示了SerializableException.serializeToBuffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPrepareShutdownSerializeError
import org.voltdb.exceptions.SerializableException; //导入方法依赖的package包/类
/**
* testPrepareShutdownSerializeError
*/
@Test
public void testPrepareShutdownSerializeError() throws Exception {
String errorMsg = "XXXXXXXXX";
Throwable error = null;
try {
throw new RuntimeException(errorMsg);
} catch (Throwable ex) {
error = ex;
}
assertNotNull(error);
SerializableException sError = new SerializableException(error);
ByteBuffer buffer = sError.serializeToBuffer();
buffer.rewind();
ShutdownPrepareRequest.Builder builder = ShutdownPrepareRequest.newBuilder()
.setSenderSite(0)
.setError(ByteString.copyFrom(buffer));
ShutdownPrepareRequest request = builder.build();
assertTrue(request.hasError());
buffer = request.getError().asReadOnlyByteBuffer();
SerializableException clone = SerializableException.deserializeFromBuffer(buffer);
assertTrue(clone.getMessage(), clone.getMessage().contains(errorMsg));
}
示例2: prepareShutdownCluster
import org.voltdb.exceptions.SerializableException; //导入方法依赖的package包/类
protected void prepareShutdownCluster(final Throwable error) throws Exception {
final CountDownLatch latch = new CountDownLatch(this.num_sites-1);
if (this.num_sites > 1) {
RpcCallback<ShutdownPrepareResponse> callback = new ShutdownPrepareCallback(this.num_sites, latch);
ShutdownPrepareRequest.Builder builder = ShutdownPrepareRequest.newBuilder()
.setSenderSite(this.catalog_site.getId());
// Pack the error into a SerializableException
if (error != null) {
SerializableException sError = new SerializableException(error);
ByteBuffer buffer = sError.serializeToBuffer();
buffer.rewind();
builder.setError(ByteString.copyFrom(buffer));
if (debug.val)
LOG.debug("Serializing error message in shutdown request");
}
ShutdownPrepareRequest request = builder.build();
if (debug.val)
LOG.debug(String.format("Sending %s to %d remote sites",
request.getClass().getSimpleName(), this.num_sites-1));
for (int site_id = 0; site_id < this.num_sites; site_id++) {
if (site_id == this.local_site_id) continue;
if (this.channels[site_id] == null) {
LOG.error(String.format("Trying to send %s to %s before the connection was established",
request.getClass().getSimpleName(),
HStoreThreadManager.formatSiteName(site_id)));
} else {
this.channels[site_id].shutdownPrepare(new ProtoRpcController(), request, callback);
if (trace.val)
LOG.trace(String.format("Sent %s to %s",
request.getClass().getSimpleName(),
HStoreThreadManager.formatSiteName(site_id)));
}
} // FOR
}
// Tell ourselves to get ready
this.hstore_site.prepareShutdown(error != null);
// Block until the latch releases us
if (this.num_sites > 1) {
LOG.info(String.format("Waiting for %d sites to finish shutting down", latch.getCount()));
boolean result = latch.await(10, TimeUnit.SECONDS);
if (result == false) {
LOG.warn("Failed to recieve all shutdown responses");
}
}
}