Skip to content

Commit

Permalink
Remove methods that allow excerpt length to be specified
Browse files Browse the repository at this point in the history
  • Loading branch information
epickrram committed Jan 4, 2018
1 parent 42bde4e commit e1fea74
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 75 deletions.
53 changes: 17 additions & 36 deletions src/main/java/net/openhft/chronicle/wire/AbstractWire.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,18 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import static net.openhft.chronicle.wire.Wires.*;
import static net.openhft.chronicle.wire.Wires.END_OF_DATA;
import static net.openhft.chronicle.wire.Wires.META_DATA;
import static net.openhft.chronicle.wire.Wires.NOT_COMPLETE;
import static net.openhft.chronicle.wire.Wires.NOT_COMPLETE_UNKNOWN_LENGTH;
import static net.openhft.chronicle.wire.Wires.NOT_INITIALIZED;
import static net.openhft.chronicle.wire.Wires.SPB_HEADER_SIZE;
import static net.openhft.chronicle.wire.Wires.UNKNOWN_LENGTH;
import static net.openhft.chronicle.wire.Wires.isData;
import static net.openhft.chronicle.wire.Wires.isNotComplete;
import static net.openhft.chronicle.wire.Wires.isReady;
import static net.openhft.chronicle.wire.Wires.isReadyMetaData;
import static net.openhft.chronicle.wire.Wires.lengthOf;

/*
* Created by Peter Lawrey on 10/03/16.
Expand Down Expand Up @@ -284,22 +295,6 @@ public void readFirstHeader(long timeout, TimeUnit timeUnit) throws TimeoutExcep
public long writeHeaderOfUnknownLength(final int safeLength, final long timeout, final TimeUnit timeUnit,
@Nullable final LongValue lastPosition, final Sequence sequence)
throws TimeoutException, EOFException {
return writeHeader(Wires.UNKNOWN_LENGTH, safeLength, timeout, timeUnit, lastPosition, sequence);
}

@Override
public long writeHeader(int length,
int safeLength,
long timeout,
TimeUnit timeUnit,
@Nullable LongValue lastPosition,
@Nullable Sequence sequence) throws TimeoutException, EOFException {

if (length != Wires.UNKNOWN_LENGTH) {
Jvm.warn().on(AbstractWire.class, "Writing a header with a known length is deprecated, " +
"and will be removed in a future release. Please use Wires.UNKNOWN_LENGTH as the length parameter.");
}

assert !insideHeader : INSIDE_HEADER_MESSAGE;

insideHeader = true;
Expand Down Expand Up @@ -414,15 +409,9 @@ private void fastForwardDontWriteHeaderNumber(long lastPositionValue) {
}

@Override
public long tryWriteHeader(int length, int safeLength) {

public long tryWriteHeader(final int safeLength) {
assert !insideHeader : INSIDE_HEADER_MESSAGE;

if (length != Wires.UNKNOWN_LENGTH) {
Jvm.warn().on(AbstractWire.class, "Writing a header with a known length is deprecated, " +
"and will be removed in a future release. Please use Wires.UNKNOWN_LENGTH as the length parameter.");
}

insideHeader = true;
try {
long tryPos = tryWriteHeader0(Wires.UNKNOWN_LENGTH, safeLength);
Expand Down Expand Up @@ -509,21 +498,14 @@ private long writeHeader0(int length, int safeLength, long timeout, TimeUnit tim
}

@Override
public void updateHeader(int length, long position, boolean metaData) throws
StreamCorruptedException, EOFException {
public void updateHeader(final long position, final boolean metaData) throws StreamCorruptedException, EOFException {
if (position <= 0) {
// this should never happen so blow up
IllegalStateException ex = new IllegalStateException("Attempt to write to position=" + position);
Slf4jExceptionHandler.WARN.on(getClass(), "Attempt to update header at position=" + position, ex);
throw ex;
}

if (length != Wires.UNKNOWN_LENGTH) {
Jvm.warn().on(AbstractWire.class, "Updating a header with a known length is deprecated, " +
"and will be removed in a future release. Please use Wires.UNKNOWN_LENGTH as the length parameter.");
}


// the reason we add padding is so that a message gets sent ( this is, mostly for queue as
// it cant handle a zero len message )
if (bytes.writePosition() == position + 4)
Expand All @@ -533,8 +515,7 @@ public void updateHeader(int length, long position, boolean metaData) throws
int actualLength = Maths.toUInt31(pos - position - 4);

int expectedHeader = NOT_COMPLETE | UNKNOWN_LENGTH;
length = actualLength;
int header = length;
int header = actualLength;
if (metaData) header |= META_DATA;
if (header == UNKNOWN_LENGTH)
throw new UnsupportedOperationException("Data messages of 0 length are not supported.");
Expand All @@ -549,7 +530,7 @@ public void updateHeader(int length, long position, boolean metaData) throws
incrementHeaderNumber(position);
}

void updateHeaderAssertions(long position, long pos, int expectedHeader, int header) throws StreamCorruptedException, EOFException {
private void updateHeaderAssertions(long position, long pos, int expectedHeader, int header) throws StreamCorruptedException, EOFException {
if (ASSERTIONS) {
checkNoDataAfterEnd(pos);
}
Expand All @@ -563,7 +544,7 @@ void updateHeaderAssertions(long position, long pos, int expectedHeader, int hea
}
}

protected void checkNoDataAfterEnd(long pos) {
private void checkNoDataAfterEnd(long pos) {
if (pos <= bytes.realCapacity() - 4) {
final int value = bytes.bytesStore().readVolatileInt(pos);
if (value != 0) {
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/net/openhft/chronicle/wire/HashWire.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.EOFException;
import java.io.ObjectOutput;
import java.io.Serializable;
import java.io.StreamCorruptedException;
Expand All @@ -42,7 +41,6 @@
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.BiConsumer;

/*
Expand Down Expand Up @@ -197,25 +195,19 @@ public DocumentContext writingDocument(boolean metaData) {
throw new UnsupportedOperationException("todo");
}

@Override
public long writeHeader(int length, int safeLength, long timeout, TimeUnit timeUnit, @Nullable LongValue lastPosition, Sequence sequence) throws TimeoutException, EOFException {
throw new UnsupportedOperationException();
}

@Override
public long writeHeaderOfUnknownLength(final int safeLength, final long timeout, final TimeUnit timeUnit,
@Nullable final LongValue lastPosition, final Sequence sequence) {
throw new UnsupportedOperationException();
}

@Override
public long tryWriteHeader(int length, int safeLength) {
public long tryWriteHeader(final int safeLength) {
throw new UnsupportedOperationException();
}

@Override
public void updateHeader(int length, long position, boolean metaData) throws
StreamCorruptedException {
public void updateHeader(long position, boolean metaData) {
throw new UnsupportedOperationException();
}

Expand Down
35 changes: 6 additions & 29 deletions src/main/java/net/openhft/chronicle/wire/WireOut.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ default void writeNotCompleteDocument(boolean metaData, @NotNull WriteMarshallab
* time.
* @param timeUnit of the timeOut
* @param lastPosition the last known position
* @param sequence
* @param sequence sequence number access
* @return the position of the start of the header
* @throws TimeoutException the underlying pauser timed out.
* @throws EOFException the end of wire marker was reached.
*/
default long writeHeader(long timeout, TimeUnit timeUnit, @Nullable final LongValue
lastPosition, Sequence sequence) throws TimeoutException, EOFException {
return writeHeader(Wires.UNKNOWN_LENGTH, timeout, timeUnit, lastPosition, sequence);
return writeHeaderOfUnknownLength(timeout, timeUnit, lastPosition, sequence);
}

/**
Expand All @@ -191,15 +191,12 @@ default long writeHeader(long timeout, TimeUnit timeUnit, @Nullable final LongVa
* @param metaData whether the message is meta data or not.
* @throws StreamCorruptedException if the steam has become corrupted
*/
default void updateHeader(long position, boolean metaData) throws StreamCorruptedException, EOFException {
updateHeader(Wires.UNKNOWN_LENGTH, position, metaData);
}
void updateHeader(long position, boolean metaData) throws StreamCorruptedException, EOFException;

/**
* Write a message of a known length, handling timeouts and the end of wire marker. This will
* Write a message of unknown length, handling timeouts and the end of wire marker. This will
* increment the headerNumber as appropriate if successful
*
* @param length the maximum length of the message.
* @param timeout throw a TimeoutException if the header could not be written in this
* time.
* @param timeUnit of the timeOut
Expand All @@ -208,14 +205,6 @@ default void updateHeader(long position, boolean metaData) throws StreamCorrupte
* @throws TimeoutException the underlying pauser timed out.
* @throws EOFException the end of wire marker was reached.
*/
default long writeHeader(int length, long timeout, TimeUnit timeUnit, @Nullable LongValue lastPosition, Sequence sequence)
throws TimeoutException, EOFException {
return writeHeader(length, DEFAULT_SAFE_LENGTH, timeout, timeUnit, lastPosition, sequence);
}

long writeHeader(int length, int safeLength, long timeout, TimeUnit timeUnit, @Nullable LongValue lastPosition, Sequence sequence)
throws TimeoutException, EOFException;

long writeHeaderOfUnknownLength(int safeLength, long timeout, TimeUnit timeUnit, @Nullable LongValue lastPosition, Sequence sequence)
throws TimeoutException, EOFException;

Expand All @@ -227,22 +216,10 @@ default long writeHeaderOfUnknownLength(long timeout, TimeUnit timeUnit, @Nullab
/**
* Makes a single attempt to try and write the header.
*
* @param length the maximum length of the message.
* @param safeLength if length is unknown (0) then assume this safe length
* @param safeLength assume this safe length
* @return TRY_WRITE_HEADER_FAILED if it failed, otherwise the position of the start of the header
*/
long tryWriteHeader(int length, int safeLength);

/**
* Change the header from NOT_COMPLETE | length to metaData * META_DATA | length.
*
* @param length provided to make the header, note this can be larger than the message
* actually used.
* @param position returned by writeHeader
* @param metaData whether the message is meta data or not.
* @throws StreamCorruptedException if the steam has become corrupted
*/
void updateHeader(int length, long position, boolean metaData) throws StreamCorruptedException, EOFException;
long tryWriteHeader(int safeLength);

/**
* Start the first header, if there is none This will increment the headerNumber as appropriate
Expand Down

0 comments on commit e1fea74

Please sign in to comment.