@Override public void sendBatch(TransportBuffer buffer) { buffer.clear(); } }
public void setTransportFactory(TransportConfig config) throws ClassNotFoundException { this.transportFactory = tff.getFactory(config); }
@Override public TransportBuffer newTransportBuffer() throws TransportException { try { return new GenericTransportBuffer(1, false, serializer); } catch (IOException e) { throw new TransportException(e); } }
/** * Drains buffer and sends batch asynchronously via {@link Transport}. * * @param buffer the buffer to send. * @param partitions the partitions associated with the buffer. */ private void send(TransportBuffer buffer, LinkedHashMap<String, String> partitions) { if (buffer.isEmpty()) { return; } this.threadCounter.incrementAndGet(); TransportThread tt = new TransportThread(transportFactory, buffer, partitions, this.threadCounter, this.hasUnrecoverableException, getRuntimeStat().fork(), getErrorCountStat(), getSuccessCountStat(), getContext()); tt.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread th, Throwable ex) { logger.error(String.format("transport thread %s failed", th.getName()), ex); } }); this.pool.execute(tt); }
@Test(expected = TransportException.class) public void testExceptionEscalation() throws TransportException, InterruptedException { DummyTransporter mockDummyTransporter = mock(DummyTransporter.class); DummyTransporterFactory tfactory = new DummyTransporterFactory(); tfactory.transporter = mockDummyTransporter; doThrow(new TransportException("expected exception in test")).when(mockDummyTransporter) .sendBatch(any(DummyTransportBuffer.class)); IpcSenderService ipc = new IpcSenderService(tfactory); ipc.add(mock(InternalEvent.class)); /* * Expect shutdown to throw a TransportException when a child thread also throws as * TransportException */ ipc.flush(); }
public IpcSenderService(TransportFactory factory) { super(factory.getChildClass()); this.transportFactory = factory; this.pool = Executors.newFixedThreadPool(factory.getMaxThreads()); this.buffers = new HashMap<LinkedHashMap<String, String>, TransportBuffer>(); }
synchronized public void shutdown() { try { flush(); } catch (InterruptedException | TransportException e) { logger.warn("caught error while flushing", e); } this.pool.shutdown(); }
public void shutdown() { if (this.getIpcService() != null) { this.getIpcService().shutdown(); } }
@Override public void sendBatch(TransportBuffer buffer) { System.out.println(buffer.getInternalBuffer().toString()); /* * Force a flush as there may not be a newline to trigger the auto flush. */ System.out.flush(); } }
@Override public boolean add(InternalEvent ievent) throws IllegalStateException, IOException { if (batchSize >= maxBatchSize) { throw new IllegalStateException("max batch size was hit"); } os.write(serializer.serialize(ievent)); batchSize++; return true; }
@Override public TransportBuffer newTransportBuffer() throws TransportException { return new DummyTransportBuffer(); }
@Override public TransportBuffer newTransportBuffer() throws TransportException { try { return new GenericTransportBuffer(1, false, serializer); } catch (IOException e) { throw new TransportException(e); } }
public IpcSenderService(TransportFactory factory) { super(factory.getChildClass()); this.transportFactory = factory; this.pool = Executors.newFixedThreadPool(factory.getMaxThreads()); this.buffers = new HashMap<LinkedHashMap<String, String>, TransportBuffer>(); }
@Override public void sendBatch(TransportBuffer buffer) { buffer.clear(); } }
public void setTransportFactory(TransportConfig config) throws ClassNotFoundException { this.transportFactory = tff.getFactory(config); }
public void shutdown() { if (this.getIpcService() != null) { this.getIpcService().shutdown(); } }
@Override public void sendBatch(TransportBuffer buffer) { System.out.println(buffer.getInternalBuffer().toString()); /* * Force a flush as there may not be a newline to trigger the auto flush. */ System.out.flush(); } }
@Override public TransportBuffer newTransportBuffer() throws TransportException { return new DummyTransportBuffer(); }
@Override public TransportBuffer newTransportBuffer() throws TransportException { try { return new GenericTransportBuffer(1, false, serializer); } catch (IOException e) { throw new TransportException(e); } }
@Override public TransportBuffer newTransportBuffer() throws TransportException { try { return new GenericTransportBuffer(1, false, serializer); } catch (IOException e) { throw new TransportException(e); } }