Java Code Examples for net.openhft.chronicle.core.Jvm#rethrow()

The following examples show how to use net.openhft.chronicle.core.Jvm#rethrow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StoreAppender.java    From Chronicle-Queue with Apache License 2.0 6 votes vote down vote up
@Override
public long lastIndexAppended() {
    throwExceptionIfClosed();

    if (lastIndex != Long.MIN_VALUE)
        return lastIndex;

    if (lastPosition == Long.MIN_VALUE || wire == null) {
        throw new IllegalStateException("nothing has been appended, so there is no last index");
    }

    try {
        long sequenceNumber = store.sequenceForPosition(this, lastPosition, true);
        long index = queue.rollCycle().toIndex(lastCycle, sequenceNumber);
        lastIndex(index);
        return index;
    } catch (Exception e) {
        throw Jvm.rethrow(e);
    }
}
 
Example 2
Source File: StoreAppender.java    From Chronicle-Queue with Apache License 2.0 6 votes vote down vote up
boolean checkWritePositionHeaderNumber() {
    if (wire == null || wire.headerNumber() == Long.MIN_VALUE) return true;
    try {
        long pos = positionOfHeader;

        long seq1 = queue.rollCycle().toSequenceNumber(wire.headerNumber() + 1) - 1;
        long seq2 = store.sequenceForPosition(this, pos, true);

        if (seq1 != seq2) {
            String message = "~~~~~~~~~~~~~~ " +
                    "thread: " + Thread.currentThread().getName() +
                    " pos: " + pos +
                    " header: " + wire.headerNumber() +
                    " seq1: " + seq1 +
                    " seq2: " + seq2;
            AssertionError ae = new AssertionError(message);
            ae.printStackTrace();
            throw ae;
        }
    } catch (Exception e) {
        // TODO FIX
        Jvm.warn().on(getClass(), e);
        throw Jvm.rethrow(e);
    }
    return true;
}
 
Example 3
Source File: StoreAppender.java    From Chronicle-Queue with Apache License 2.0 6 votes vote down vote up
/**
 * pretouch() has to be run on the same thread, as the thread that created the appender. If you want to use pretouch() in another thread, you
 * must first create or have an appender that was created on this thread, and then use this appender to call the pretouch()
 */
@Override
public void pretouch() {
    throwExceptionIfClosed();

    if (queue.isClosed())
        throw new RuntimeException("Queue Closed");
    try {
        if (pretoucher == null)
            pretoucher = new Pretoucher(queue());

        pretoucher.execute();
    } catch (Throwable e) {
        Jvm.warn().on(getClass(), e);
        Jvm.rethrow(e);
    }
}
 
Example 4
Source File: TcpEventHandler.java    From Chronicle-Network with Apache License 2.0 6 votes vote down vote up
@Override
public boolean action() throws InvalidEventHandlerException {
    Jvm.optionalSafepoint();

    if (this.isClosed())
        throw new InvalidEventHandlerException();
    if (actionThread == null)
        actionThread = Thread.currentThread();
    QueryCloseable c = sc;
    if (c.isClosed())
        throw new InvalidEventHandlerException();

    if (tcpHandler == null)
        return false;

    try {
        return action0();
    } catch (Throwable t) {
        if (this.isClosed())
            throw new InvalidEventHandlerException();
        throw Jvm.rethrow(t);
    }
}
 
Example 5
Source File: AbstractStatelessClient.java    From Chronicle-Network with Apache License 2.0 6 votes vote down vote up
private <R> R readReply(@NotNull final WireIn wireIn,
                        @NotNull final WireKey replyId,
                        @NotNull final Function<ValueIn, R> function) {

    final StringBuilder eventName = Wires.acquireStringBuilder();
    @NotNull final ValueIn event = wireIn.read(eventName);

    if (replyId.contentEquals(eventName))
        return function.apply(event);

    if (CoreFields.exception.contentEquals(eventName)) {
        throw Jvm.rethrow(event.throwable(true));
    }

    throw new UnsupportedOperationException("unknown event=" + eventName);
}
 
Example 6
Source File: JSR166TestCase.java    From Chronicle-Map with Apache License 2.0 6 votes vote down vote up
/**
 * Extra checks that get done for all test cases.
 * <p>
 * <p>Triggers test case Assert.failure if any thread assertions have Assert.failed,
 * by rethrowing, in the test harness thread, any exception recorded
 * earlier by threadRecordFailure.
 * <p>
 * <p>Triggers test case Assert.failure if interrupt status is set in the main thread.
 */
@After
public void tearDown() throws InterruptedException {
    Throwable t = threadFailure.getAndSet(null);
    if (t != null) {
        if (t instanceof Error)
            throw (Error) t;
        else if (t instanceof RuntimeException)
            throw (RuntimeException) t;
        else if (t instanceof Exception)
            throw Jvm.rethrow(t);
        else {
            AssertionFailedError afe =
                    new AssertionFailedError(t.toString());
            afe.initCause(t);
            throw afe;
        }
    }

    if (Thread.interrupted())
        throw new AssertionFailedError("interrupt status set in main thread");

    checkForkJoinPoolThreadLeaks();
    System.gc();
}
 
Example 7
Source File: BigSegmentHeader.java    From Chronicle-Map with Apache License 2.0 5 votes vote down vote up
private static RuntimeException tryDeregisterWaitAndRethrow(long address, Throwable throwable) {
    try {
        deregisterWait(address);
    } catch (Throwable t) {
        throwable.addSuppressed(t);
    }
    throw Jvm.rethrow(throwable);
}
 
Example 8
Source File: RollCycleMultiThreadStressSharedWriterQueueTest.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
@Test
public void stress() throws InterruptedException, IOException {
    try {
        FlakyTestRunner.run(super::stress);
    } catch (Exception e) {
        throw Jvm.rethrow(e);
    }
}
 
Example 9
Source File: MethodReaderQueueEntryHandler.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
public MethodReaderQueueEntryHandler(String methodReaderInterface) {
    try {
        mrInterface = Class.forName(methodReaderInterface);
    } catch (ClassNotFoundException e) {
        throw Jvm.rethrow(e);
    }
}
 
Example 10
Source File: OMSImplTest.java    From Chronicle-Queue-Demo with Apache License 2.0 5 votes vote down vote up
public static void runTest(String path) {
    String input = "src/test/resources/" + path + "/in.yaml";
    String output = "src/test/resources/" + path + "/out.yaml";
    TextMethodTester tester = new TextMethodTester<>(input, OMSImpl::new, OMSOut.class, output);
    try {
        tester.run();
        assertEquals(tester.expected(), tester.actual());
    } catch (IOException e) {
        Jvm.rethrow(e);
    }
}
 
Example 11
Source File: WireOutPublisher.java    From Chronicle-Network with Apache License 2.0 5 votes vote down vote up
/**
 * a static factory that creates and instance in chronicle enterprise
 *
 * @param periodMs the period between updates of the same key
 * @param delegate the  WireOutPublisher the events will get delegated to
 * @return a throttled WireOutPublisher
 */
static WireOutPublisher newThrottledWireOutPublisher(int periodMs, @NotNull WireOutPublisher delegate) {

    try {
        final Class<?> aClass = Class.forName("software.chronicle.enterprise.throttle.ThrottledWireOutPublisher");
        @NotNull final Constructor<WireOutPublisher> constructor = (Constructor) aClass.getConstructors()[0];
        return constructor.newInstance(periodMs, delegate);

    } catch (Exception e) {
        Jvm.warn().on(WireOutPublisher.class, "To use this feature please install Chronicle-Engine-Enterprise");
        throw Jvm.rethrow(e);
    }
}
 
Example 12
Source File: EventWithHistoryMethodWriter.java    From Chronicle-Queue-Demo with Apache License 2.0 5 votes vote down vote up
public void close() {
  Method _method_ = this.methods[3];
  Object[] _a_ = this.argsTL.get()[0];
  try {
    handler.get().invoke(this, _method_, _a_);
  } catch (Throwable throwable) {
    throw Jvm.rethrow(throwable);
  }
}
 
Example 13
Source File: EventWithHistoryMethodWriter.java    From Chronicle-Queue-Demo with Apache License 2.0 5 votes vote down vote up
public void eventTwo(town.lost.processor.events.EventTwo arg0) {
  Method _method_ = this.methods[2];
  Object[] _a_ = this.argsTL.get()[1];
  _a_[0] = arg0;
  try {
    handler.get().invoke(this, _method_, _a_);
  } catch (Throwable throwable) {
    throw Jvm.rethrow(throwable);
  }
}
 
Example 14
Source File: EventWithHistoryMethodWriter.java    From Chronicle-Queue-Demo with Apache License 2.0 5 votes vote down vote up
public void eventOne(town.lost.processor.events.EventOne arg0) {
  Method _method_ = this.methods[1];
  Object[] _a_ = this.argsTL.get()[1];
  _a_[0] = arg0;
  try {
    handler.get().invoke(this, _method_, _a_);
  } catch (Throwable throwable) {
    throw Jvm.rethrow(throwable);
  }
}
 
Example 15
Source File: EventWithHistoryMethodWriter.java    From Chronicle-Queue-Demo with Apache License 2.0 5 votes vote down vote up
public town.lost.processor.events.EventWithHistory history(net.openhft.chronicle.wire.VanillaMessageHistory arg0) {
  Method _method_ = this.methods[0];
  Object[] _a_ = this.argsTL.get()[1];
  _a_[0] = arg0;
  try {
    return (town.lost.processor.events.EventWithHistory) handler.get().invoke(this, _method_, _a_);
  } catch (Throwable throwable) {
    throw Jvm.rethrow(throwable);
  }
}
 
Example 16
Source File: AvroHelper.java    From Chronicle-Queue-Demo with Apache License 2.0 5 votes vote down vote up
AvroHelper() {
    try {
        schema = new Schema.Parser().parse(getClass().getClassLoader().getResourceAsStream("user.avsc"));
        datumWriter = new GenericDatumWriter<>(schema);
        datumReader = new GenericDatumReader<>(schema);
    } catch (IOException ex) {
        Jvm.rethrow(ex);
    }
}
 
Example 17
Source File: SingleChronicleQueue.java    From Chronicle-Queue with Apache License 2.0 4 votes vote down vote up
protected SingleChronicleQueue(@NotNull final SingleChronicleQueueBuilder builder) {
    try {
        rollCycle = builder.rollCycle();
        cycleCalculator = cycleCalculator(builder.rollTimeZone());
        epoch = builder.epoch();
        dateCache = new RollingResourcesCache(rollCycle, epoch, textToFile(builder), fileToText());

        storeFileListener = builder.storeFileListener();
        storeSupplier = new StoreSupplier();
        pool = WireStorePool.withSupplier(storeSupplier, storeFileListener);
        isBuffered = BufferMode.Asynchronous == builder.writeBufferMode();
        path = builder.path();
        if (!builder.readOnly())
            //noinspection ResultOfMethodCallIgnored
            path.mkdirs();
        fileAbsolutePath = path.getAbsolutePath();
        wireType = builder.wireType();
        blockSize = builder.blockSize();
        overlapSize = Math.max(64 << 10, builder.blockSize() / 4);
        eventLoop = builder.eventLoop();
        bufferCapacity = builder.bufferCapacity();
        onRingBufferStats = builder.onRingBufferStats();
        indexCount = builder.indexCount();
        indexSpacing = builder.indexSpacing();
        time = builder.timeProvider();
        pauserSupplier = builder.pauserSupplier();
        // add a 10% random element to make it less likely threads will timeout at the same time.
        timeoutMS = (long) (builder.timeoutMS() * (1 + 0.2 * ThreadLocalRandom.current().nextFloat()));
        storeFactory = builder.storeFactory();
        checkInterrupts = builder.checkInterrupts();
        metaStore = builder.metaStore();
        doubleBuffer = builder.doubleBuffer();
        if (metaStore.readOnly() && !builder.readOnly()) {
            LOG.warn("Forcing queue to be readOnly");
            // need to set this on builder as it is used elsewhere
            builder.readOnly(metaStore.readOnly());
        }
        readOnly = builder.readOnly();

        if (readOnly) {
            this.directoryListing = new FileSystemDirectoryListing(path, fileToCycleFunction());
        } else {
            this.directoryListing = new TableDirectoryListing(metaStore, path.toPath(), fileToCycleFunction(), false);
            directoryListing.init();
        }

        this.directoryListing.refresh();
        this.queueLock = builder.queueLock();
        this.writeLock = builder.writeLock();

        if (readOnly) {
            this.lastIndexReplicated = null;
            this.lastAcknowledgedIndexReplicated = null;
        } else {
            this.lastIndexReplicated = metaStore.doWithExclusiveLock(ts -> ts.acquireValueFor("chronicle.lastIndexReplicated", -1L));
            this.lastAcknowledgedIndexReplicated = metaStore.doWithExclusiveLock(ts -> ts.acquireValueFor("chronicle.lastAcknowledgedIndexReplicated", -1L));
        }

        this.deltaCheckpointInterval = builder.deltaCheckpointInterval();

        sourceId = builder.sourceId();
    } catch (Throwable t) {
        close();
        throw Jvm.rethrow(t);
    }
}
 
Example 18
Source File: CountingJDBCResult.java    From Chronicle-Queue with Apache License 2.0 4 votes vote down vote up
@Override
public void queryThrown(Throwable t, String query, Object... args) {
    throw Jvm.rethrow(t);
}
 
Example 19
Source File: CountingJDBCResult.java    From Chronicle-Queue with Apache License 2.0 4 votes vote down vote up
@Override
public void updateThrown(Throwable t, String update, Object... args) {
    throw Jvm.rethrow(t);
}