@Override public void run(TransactionRedirectResponse parameter) { if (LOG.isTraceEnabled()) LOG.trace( String.format( "Got back FORWARD_TXN response from %s. Sending response to client [bytes=%d]", HStoreSite.formatSiteName(parameter.getSenderId()), parameter.getOutput().size())); byte data[] = parameter.getOutput().toByteArray(); try { this.orig_callback.run(data); } catch (Throwable ex) { FastDeserializer fds = new FastDeserializer(data); ClientResponseImpl cresponse = null; long txn_id = -1; try { cresponse = fds.readObject(ClientResponseImpl.class); txn_id = cresponse.getTransactionId(); } catch (IOException e) { LOG.fatal("We're really falling apart here!", e); } LOG.fatal("Failed to forward ClientResponse data back for txn #" + txn_id, ex); // throw ex; } finally { try { this.finish(); HStoreObjectPools.CALLBACKS_TXN_REDIRECT_REQUEST.returnObject(this); } catch (Exception ex) { throw new RuntimeException("Funky failure", ex); } } }
@Override public void run(ClientResponseImpl parameter) { if (debug.get()) LOG.debug( String.format( "Got ClientResponse callback for txn #%d! Sending back to %s", parameter.getTransactionId(), HStoreThreadManager.formatSiteName(this.destSiteId))); FastSerializer fs = new FastSerializer(); try { parameter.writeExternal(fs); } catch (IOException ex) { throw new RuntimeException(ex); } ByteString bs = ByteString.copyFrom(fs.getBuffer()); TransactionRedirectResponse response = TransactionRedirectResponse.newBuilder() .setSenderSite(this.sourceSiteId) .setOutput(bs) .build(); this.orig_callback.run(response); if (debug.get()) LOG.debug( String.format( "Sent back ClientResponse for txn #%d to %s [bytes=%d]", parameter.getTransactionId(), HStoreThreadManager.formatSiteName(this.destSiteId))); // IMPORTANT: Since we're the only one that knows that we're finished (and actually even // cares), we need to be polite and clean-up after ourselves... try { this.finish(); hstore_site.getObjectPools().CALLBACKS_TXN_REDIRECT_RESPONSE.returnObject(this); } catch (Exception ex) { throw new RuntimeException("Funky failure", ex); } }