Refine search
@Override public long recoverAndWriteHeader(@NotNull Wire wire, long timeoutMS, @NotNull final LongValue lastPosition, Sequence sequence) throws UnrecoverableTimeoutException { Jvm.warn().on(getClass(), "Clearing an incomplete header so a header can be written"); wire.bytes().writeInt(0); wire.pauser().reset(); try { return wire.writeHeaderOfUnknownLength(timeoutMS, TimeUnit.MILLISECONDS, lastPosition, sequence); } catch (@NotNull TimeoutException | EOFException e) { throw new UnrecoverableTimeoutException(e); } } }
@Override public synchronized void release(@NotNull CommonStore store) { store.release(); long refCount = store.refCount(); assert refCount >= 0; if (refCount == 0) { for (Map.Entry<RollDetails, WeakReference<WireStore>> entry : stores.entrySet()) { WeakReference<WireStore> ref = entry.getValue(); if (ref != null && ref.get() == store) { stores.remove(entry.getKey()); storeFileListener.onReleased(entry.getKey().cycle(), store.file()); return; } } if (Jvm.isDebugEnabled(getClass())) Jvm.debug().on(getClass(), "Store was not registered: " + store.file()); } }
@Override public void writeEOF(@NotNull Wire wire, long timeoutMS) { // just in case we are about to release this if (wire.bytes().tryReserve()) { wire.writeEndOfWire(timeoutMS, TimeUnit.MILLISECONDS, writePosition()); wire.bytes().release(); } else { Jvm.debug().on(getClass(), "Tried to writeEOF to as it was being closed"); } }
public static void renamePreCreatedFileToRequiredFile(final File requiredQueueFile) { final File preCreatedFile = preCreatedFile(requiredQueueFile); if (preCreatedFile.exists()) { if (!preCreatedFile.renameTo(requiredQueueFile)) { Jvm.warn().on(PrecreatedFiles.class, "Failed to rename pre-created queue file"); } } }
public void writeBytes(long index, @NotNull BytesStore bytes) { throw new IllegalStateException("Unable to move to index " + Long.toHexString(index) + " beyond the end of the queue"); Jvm.warn().on(getClass(), "Trying to overwrite index " + Long.toHexString(index) + " which is before the end of the queue"); return;
@Override public long recoverAndWriteHeader(@NotNull Wire wire, long timeoutMS, final LongValue lastPosition, Sequence sequence) throws UnrecoverableTimeoutException { Bytes<?> bytes = wire.bytes(); warn().on(getClass(), msgStart + " switching to a corrupt meta data message"); bytes.writeSkip(sizeToSkip + 4); } else { int num2 = bytes.readVolatileInt(offset); warn().on(getClass(), msgStart + " already set to " + Integer.toHexString(num2)); warn().on(getClass(), msgStart + " but message now exists."); warn().on(getClass(), e);
private long writeHeader(@NotNull Wire wire, int safeLength) { Bytes<?> bytes = wire.bytes(); // writePosition points at the last record in the queue, so we can just skip it and we're ready for write long pos = position; long lastPos = store.writePosition(); if (pos < lastPos) { // queue moved since we last touched it - recalculate header number try { wire.headerNumber(queue.rollCycle().toIndex(cycle, store.lastSequenceNumber(this))); } catch (StreamCorruptedException ex) { Jvm.warn().on(getClass(), "Couldn't find last sequence", ex); } } int header = bytes.readVolatileInt(lastPos); assert header != NOT_INITIALIZED; lastPos += lengthOf(bytes.readVolatileInt(lastPos)) + SPB_HEADER_SIZE; bytes.writePosition(lastPos); return wire.enterHeader(safeLength); }
long sequenceForPosition(@NotNull ExcerptContext ec, final long position, boolean inclusive) throws StreamCorruptedException { long indexOfNext = 0; long lastKnownAddress = 0; @NotNull Wire wire = ec.wireForIndex(); try { final LongArrayValues index2indexArr = getIndex2index(wire); Jvm.debug().on(getClass(), "Attempt to find " + Long.toHexString(position), e);
/** * Checks if the lock is held by current thread and if so, releases it, removing entry from TableStore and clearing * ThreadLocal state, allowing anyone to proceed with {@link net.openhft.chronicle.queue.ChronicleQueue#acquireAppender}. */ @Override public void unlock() { closeCheck(); if (!isLockHeldByCurrentThread()) throw new IllegalStateException("Can't unlock when lock is not held by this thread"); if (!lock.compareAndSwapValue(PID, UNLOCKED)) { warn().on(getClass(), "Queue lock was unlocked by someone else!"); } lockHolderTidTL.remove(); }
private static void deleteFiles(@NotNull File element) throws IOException { if (element.isDirectory()) { @Nullable File[] files = element.listFiles(); if (files == null) return; for (@NotNull File sub : files) { deleteFiles(sub); } } try { Files.deleteIfExists(element.toPath()); } catch (IOException e) { Jvm.debug().on(ChronicleQueueView.class, "Unable to delete " + element, e); } }
private static void registerTreeWithMBean(AssetTreeDynamicMBean atBean, ObjectName atName) { try { if (mbs != null && !mbs.isRegistered(atName)) { mbs.registerMBean(atBean, atName); } } catch (@NotNull InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) { Jvm.warn().on(ManagementTools.class, "Error register AssetTree with MBean", e); } }
@Override public void onEndOfConnection(boolean heartbeatTimeOut) { for (@NotNull final AbstractHandler abstractHandler : new AbstractHandler[]{mapWireHandler, subscriptionHandler, topologySubscriptionHandler, publisherHandler, replicationHandler}) { try { abstractHandler.onEndOfConnection(); } catch (Exception e) { Jvm.debug().on(getClass(), "Failed while for " + abstractHandler, e); } } }