當前位置: 首頁>>代碼示例>>Java>>正文


Java SerializableException.serializeToBuffer方法代碼示例

本文整理匯總了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));
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:28,代碼來源:TestHStoreCoordinator.java

示例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");
        }
    }
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:51,代碼來源:HStoreCoordinator.java


注:本文中的org.voltdb.exceptions.SerializableException.serializeToBuffer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。