cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r915428 [2/3] - in /incubator/cassandra/tags/cassandra-0.6.0-beta1: ./ contrib/word_count/src/ interface/thrift/gen-java/org/apache/cassandra/thrift/ src/java/org/apache/cassandra/cache/ src/java/org/apache/cassandra/db/commitlog/ src/java/...
Date Tue, 23 Feb 2010 16:57:53 GMT
Modified: incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/io/util/MappedFileDataInput.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/io/util/MappedFileDataInput.java?rev=915428&r1=915421&r2=915428&view=diff
==============================================================================
--- incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/io/util/MappedFileDataInput.java (original)
+++ incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/io/util/MappedFileDataInput.java Tue Feb 23 16:57:51 2010
@@ -1,404 +1,404 @@
-package org.apache.cassandra.io.util;
-
-import java.nio.MappedByteBuffer;
-import java.io.*;
-
-public class MappedFileDataInput extends InputStream implements FileDataInput
-{
-    private final MappedByteBuffer buffer;
-    private final String filename;
-    private int position;
-    private int markedPosition;
-
-    public MappedFileDataInput(MappedByteBuffer buffer, String filename)
-    {
-        this(buffer, filename, 0);
-    }
-
-    public MappedFileDataInput(MappedByteBuffer buffer, String filename, int position)
-    {
-        assert buffer != null;
-        this.buffer = buffer;
-        this.filename = filename;
-        this.position = position;
-    }
-
-    // don't make this public, this is only for seeking WITHIN the current mapped segment
-    private void seekInternal(int pos) throws IOException
-    {
-        position = pos;
-    }
-
-    @Override
-    public boolean markSupported()
-    {
-        return true;
-    }
-
-    @Override
-    public void mark(int ignored)
-    {
-        markedPosition = position;
-    }
-
-    @Override
-    public void reset() throws IOException
-    {
-        seekInternal(markedPosition);
-    }
-
-    public void mark()
-    {
-        mark(-1);
-    }
-
-    public int bytesPastMark()
-    {
-        assert position >= markedPosition;
-        return position - markedPosition;
-    }
-
-    public boolean isEOF() throws IOException
-    {
-        return position == buffer.capacity();
-    }
-
-    public String getPath()
-    {
-        return filename;
-    }
-
-    public int read() throws IOException
-    {
-        if (isEOF())
-            return -1;
-        return buffer.get(position++) & 0xFF;
-    }
-
-    public int skipBytes(int n) throws IOException
-    {
-        if (n <= 0)
-            return 0;
-        int oldPosition = position;
-        assert ((long)oldPosition) + n <= Integer.MAX_VALUE;
-        position = Math.min(buffer.capacity(), position + n);
-        return position - oldPosition;
-    }
-
-    /*
-     !! DataInput methods below are copied from the implementation in Apache Harmony RandomAccessFile.
-     */
-
-    /**
-     * Reads a boolean from the current position in this file. Blocks until one
-     * byte has been read, the end of the file is reached or an exception is
-     * thrown.
-     *
-     * @return the next boolean value from this file.
-     * @throws EOFException
-     *             if the end of this file is detected.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     */
-    public final boolean readBoolean() throws IOException {
-        int temp = this.read();
-        if (temp < 0) {
-            throw new EOFException();
-        }
-        return temp != 0;
-    }
-
-    /**
-     * Reads an 8-bit byte from the current position in this file. Blocks until
-     * one byte has been read, the end of the file is reached or an exception is
-     * thrown.
-     *
-     * @return the next signed 8-bit byte value from this file.
-     * @throws EOFException
-     *             if the end of this file is detected.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     */
-    public final byte readByte() throws IOException {
-        int temp = this.read();
-        if (temp < 0) {
-            throw new EOFException();
-        }
-        return (byte) temp;
-    }
-
-    /**
-     * Reads a 16-bit character from the current position in this file. Blocks until
-     * two bytes have been read, the end of the file is reached or an exception is
-     * thrown.
-     *
-     * @return the next char value from this file.
-     * @throws EOFException
-     *             if the end of this file is detected.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     */
-    public final char readChar() throws IOException {
-        byte[] buffer = new byte[2];
-        if (read(buffer, 0, buffer.length) != buffer.length) {
-            throw new EOFException();
-        }
-        return (char) (((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff));
-    }
-
-    /**
-     * Reads a 64-bit double from the current position in this file. Blocks
-     * until eight bytes have been read, the end of the file is reached or an
-     * exception is thrown.
-     *
-     * @return the next double value from this file.
-     * @throws EOFException
-     *             if the end of this file is detected.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     */
-    public final double readDouble() throws IOException {
-        return Double.longBitsToDouble(readLong());
-    }
-
-    /**
-     * Reads a 32-bit float from the current position in this file. Blocks
-     * until four bytes have been read, the end of the file is reached or an
-     * exception is thrown.
-     *
-     * @return the next float value from this file.
-     * @throws EOFException
-     *             if the end of this file is detected.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     */
-    public final float readFloat() throws IOException {
-        return Float.intBitsToFloat(readInt());
-    }
-
-    /**
-     * Reads bytes from this file into {@code buffer}. Blocks until {@code
-     * buffer.length} number of bytes have been read, the end of the file is
-     * reached or an exception is thrown.
-     *
-     * @param buffer
-     *            the buffer to read bytes into.
-     * @throws EOFException
-     *             if the end of this file is detected.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     * @throws NullPointerException
-     *             if {@code buffer} is {@code null}.
-     */
-    public final void readFully(byte[] buffer) throws IOException {
-        readFully(buffer, 0, buffer.length);
-    }
-
-    /**
-     * Read bytes from this file into {@code buffer} starting at offset {@code
-     * offset}. This method blocks until {@code count} number of bytes have been
-     * read.
-     *
-     * @param buffer
-     *            the buffer to read bytes into.
-     * @param offset
-     *            the initial position in {@code buffer} to store the bytes read
-     *            from this file.
-     * @param count
-     *            the maximum number of bytes to store in {@code buffer}.
-     * @throws EOFException
-     *             if the end of this file is detected.
-     * @throws IndexOutOfBoundsException
-     *             if {@code offset < 0} or {@code count < 0}, or if {@code
-     *             offset + count} is greater than the length of {@code buffer}.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     * @throws NullPointerException
-     *             if {@code buffer} is {@code null}.
-     */
-    public final void readFully(byte[] buffer, int offset, int count)
-            throws IOException {
-        if (buffer == null) {
-            throw new NullPointerException();
-        }
-        // avoid int overflow
-        if (offset < 0 || offset > buffer.length || count < 0
-                || count > buffer.length - offset) {
-            throw new IndexOutOfBoundsException();
-        }
-        while (count > 0) {
-            int result = read(buffer, offset, count);
-            if (result < 0) {
-                throw new EOFException();
-            }
-            offset += result;
-            count -= result;
-        }
-    }
-
-    /**
-     * Reads a 32-bit integer from the current position in this file. Blocks
-     * until four bytes have been read, the end of the file is reached or an
-     * exception is thrown.
-     *
-     * @return the next int value from this file.
-     * @throws EOFException
-     *             if the end of this file is detected.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     */
-    public final int readInt() throws IOException {
-        byte[] buffer = new byte[4];
-        if (read(buffer, 0, buffer.length) != buffer.length) {
-            throw new EOFException();
-        }
-        return ((buffer[0] & 0xff) << 24) + ((buffer[1] & 0xff) << 16)
-                + ((buffer[2] & 0xff) << 8) + (buffer[3] & 0xff);
-    }
-
-    /**
-     * Reads a line of text form the current position in this file. A line is
-     * represented by zero or more characters followed by {@code '\n'}, {@code
-     * '\r'}, {@code "\r\n"} or the end of file marker. The string does not
-     * include the line terminating sequence.
-     * <p>
-     * Blocks until a line terminating sequence has been read, the end of the
-     * file is reached or an exception is thrown.
-     *
-     * @return the contents of the line or {@code null} if no characters have
-     *         been read before the end of the file has been reached.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     */
-    public final String readLine() throws IOException {
-        StringBuilder line = new StringBuilder(80); // Typical line length
-        boolean foundTerminator = false;
-        int unreadPosition = 0;
-        while (true) {
-            int nextByte = read();
-            switch (nextByte) {
-                case -1:
-                    return line.length() != 0 ? line.toString() : null;
-                case (byte) '\r':
-                    if (foundTerminator) {
-                        seekInternal(unreadPosition);
-                        return line.toString();
-                    }
-                    foundTerminator = true;
-                    /* Have to be able to peek ahead one byte */
-                    unreadPosition = position;
-                    break;
-                case (byte) '\n':
-                    return line.toString();
-                default:
-                    if (foundTerminator) {
-                        seekInternal(unreadPosition);
-                        return line.toString();
-                    }
-                    line.append((char) nextByte);
-            }
-        }
-    }
-
-    /**
-     * Reads a 64-bit long from the current position in this file. Blocks until
-     * eight bytes have been read, the end of the file is reached or an
-     * exception is thrown.
-     *
-     * @return the next long value from this file.
-     * @throws EOFException
-     *             if the end of this file is detected.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     */
-    public final long readLong() throws IOException {
-        byte[] buffer = new byte[8];
-        int n = read(buffer, 0, buffer.length);
-        if (n != buffer.length) {
-            throw new EOFException("expected 8 bytes; read " + n + " at final position " + position);
-        }
-        return ((long) (((buffer[0] & 0xff) << 24) + ((buffer[1] & 0xff) << 16)
-                + ((buffer[2] & 0xff) << 8) + (buffer[3] & 0xff)) << 32)
-                + ((long) (buffer[4] & 0xff) << 24)
-                + ((buffer[5] & 0xff) << 16)
-                + ((buffer[6] & 0xff) << 8)
-                + (buffer[7] & 0xff);
-    }
-
-    /**
-     * Reads a 16-bit short from the current position in this file. Blocks until
-     * two bytes have been read, the end of the file is reached or an exception
-     * is thrown.
-     *
-     * @return the next short value from this file.
-     * @throws EOFException
-     *             if the end of this file is detected.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     */
-    public final short readShort() throws IOException {
-        byte[] buffer = new byte[2];
-        if (read(buffer, 0, buffer.length) != buffer.length) {
-            throw new EOFException();
-        }
-        return (short) (((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff));
-    }
-
-    /**
-     * Reads an unsigned 8-bit byte from the current position in this file and
-     * returns it as an integer. Blocks until one byte has been read, the end of
-     * the file is reached or an exception is thrown.
-     *
-     * @return the next unsigned byte value from this file as an int.
-     * @throws EOFException
-     *             if the end of this file is detected.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     */
-    public final int readUnsignedByte() throws IOException {
-        int temp = this.read();
-        if (temp < 0) {
-            throw new EOFException();
-        }
-        return temp;
-    }
-
-    /**
-     * Reads an unsigned 16-bit short from the current position in this file and
-     * returns it as an integer. Blocks until two bytes have been read, the end of
-     * the file is reached or an exception is thrown.
-     *
-     * @return the next unsigned short value from this file as an int.
-     * @throws EOFException
-     *             if the end of this file is detected.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     */
-    public final int readUnsignedShort() throws IOException {
-        byte[] buffer = new byte[2];
-        if (read(buffer, 0, buffer.length) != buffer.length) {
-            throw new EOFException();
-        }
-        return ((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff);
-    }
-
-    /**
-     * Reads a string that is encoded in {@link DataInput modified UTF-8} from
-     * this file. The number of bytes that must be read for the complete string
-     * is determined by the first two bytes read from the file. Blocks until all
-     * required bytes have been read, the end of the file is reached or an
-     * exception is thrown.
-     *
-     * @return the next string encoded in {@link DataInput modified UTF-8} from
-     *         this file.
-     * @throws EOFException
-     *             if the end of this file is detected.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     * @throws UTFDataFormatException
-     *             if the bytes read cannot be decoded into a character string.
-     */
-    public final String readUTF() throws IOException {
-        return DataInputStream.readUTF(this);
-    }
-}
+package org.apache.cassandra.io.util;
+
+import java.nio.MappedByteBuffer;
+import java.io.*;
+
+public class MappedFileDataInput extends InputStream implements FileDataInput
+{
+    private final MappedByteBuffer buffer;
+    private final String filename;
+    private int position;
+    private int markedPosition;
+
+    public MappedFileDataInput(MappedByteBuffer buffer, String filename)
+    {
+        this(buffer, filename, 0);
+    }
+
+    public MappedFileDataInput(MappedByteBuffer buffer, String filename, int position)
+    {
+        assert buffer != null;
+        this.buffer = buffer;
+        this.filename = filename;
+        this.position = position;
+    }
+
+    // don't make this public, this is only for seeking WITHIN the current mapped segment
+    private void seekInternal(int pos) throws IOException
+    {
+        position = pos;
+    }
+
+    @Override
+    public boolean markSupported()
+    {
+        return true;
+    }
+
+    @Override
+    public void mark(int ignored)
+    {
+        markedPosition = position;
+    }
+
+    @Override
+    public void reset() throws IOException
+    {
+        seekInternal(markedPosition);
+    }
+
+    public void mark()
+    {
+        mark(-1);
+    }
+
+    public int bytesPastMark()
+    {
+        assert position >= markedPosition;
+        return position - markedPosition;
+    }
+
+    public boolean isEOF() throws IOException
+    {
+        return position == buffer.capacity();
+    }
+
+    public String getPath()
+    {
+        return filename;
+    }
+
+    public int read() throws IOException
+    {
+        if (isEOF())
+            return -1;
+        return buffer.get(position++) & 0xFF;
+    }
+
+    public int skipBytes(int n) throws IOException
+    {
+        if (n <= 0)
+            return 0;
+        int oldPosition = position;
+        assert ((long)oldPosition) + n <= Integer.MAX_VALUE;
+        position = Math.min(buffer.capacity(), position + n);
+        return position - oldPosition;
+    }
+
+    /*
+     !! DataInput methods below are copied from the implementation in Apache Harmony RandomAccessFile.
+     */
+
+    /**
+     * Reads a boolean from the current position in this file. Blocks until one
+     * byte has been read, the end of the file is reached or an exception is
+     * thrown.
+     *
+     * @return the next boolean value from this file.
+     * @throws EOFException
+     *             if the end of this file is detected.
+     * @throws IOException
+     *             if this file is closed or another I/O error occurs.
+     */
+    public final boolean readBoolean() throws IOException {
+        int temp = this.read();
+        if (temp < 0) {
+            throw new EOFException();
+        }
+        return temp != 0;
+    }
+
+    /**
+     * Reads an 8-bit byte from the current position in this file. Blocks until
+     * one byte has been read, the end of the file is reached or an exception is
+     * thrown.
+     *
+     * @return the next signed 8-bit byte value from this file.
+     * @throws EOFException
+     *             if the end of this file is detected.
+     * @throws IOException
+     *             if this file is closed or another I/O error occurs.
+     */
+    public final byte readByte() throws IOException {
+        int temp = this.read();
+        if (temp < 0) {
+            throw new EOFException();
+        }
+        return (byte) temp;
+    }
+
+    /**
+     * Reads a 16-bit character from the current position in this file. Blocks until
+     * two bytes have been read, the end of the file is reached or an exception is
+     * thrown.
+     *
+     * @return the next char value from this file.
+     * @throws EOFException
+     *             if the end of this file is detected.
+     * @throws IOException
+     *             if this file is closed or another I/O error occurs.
+     */
+    public final char readChar() throws IOException {
+        byte[] buffer = new byte[2];
+        if (read(buffer, 0, buffer.length) != buffer.length) {
+            throw new EOFException();
+        }
+        return (char) (((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff));
+    }
+
+    /**
+     * Reads a 64-bit double from the current position in this file. Blocks
+     * until eight bytes have been read, the end of the file is reached or an
+     * exception is thrown.
+     *
+     * @return the next double value from this file.
+     * @throws EOFException
+     *             if the end of this file is detected.
+     * @throws IOException
+     *             if this file is closed or another I/O error occurs.
+     */
+    public final double readDouble() throws IOException {
+        return Double.longBitsToDouble(readLong());
+    }
+
+    /**
+     * Reads a 32-bit float from the current position in this file. Blocks
+     * until four bytes have been read, the end of the file is reached or an
+     * exception is thrown.
+     *
+     * @return the next float value from this file.
+     * @throws EOFException
+     *             if the end of this file is detected.
+     * @throws IOException
+     *             if this file is closed or another I/O error occurs.
+     */
+    public final float readFloat() throws IOException {
+        return Float.intBitsToFloat(readInt());
+    }
+
+    /**
+     * Reads bytes from this file into {@code buffer}. Blocks until {@code
+     * buffer.length} number of bytes have been read, the end of the file is
+     * reached or an exception is thrown.
+     *
+     * @param buffer
+     *            the buffer to read bytes into.
+     * @throws EOFException
+     *             if the end of this file is detected.
+     * @throws IOException
+     *             if this file is closed or another I/O error occurs.
+     * @throws NullPointerException
+     *             if {@code buffer} is {@code null}.
+     */
+    public final void readFully(byte[] buffer) throws IOException {
+        readFully(buffer, 0, buffer.length);
+    }
+
+    /**
+     * Read bytes from this file into {@code buffer} starting at offset {@code
+     * offset}. This method blocks until {@code count} number of bytes have been
+     * read.
+     *
+     * @param buffer
+     *            the buffer to read bytes into.
+     * @param offset
+     *            the initial position in {@code buffer} to store the bytes read
+     *            from this file.
+     * @param count
+     *            the maximum number of bytes to store in {@code buffer}.
+     * @throws EOFException
+     *             if the end of this file is detected.
+     * @throws IndexOutOfBoundsException
+     *             if {@code offset < 0} or {@code count < 0}, or if {@code
+     *             offset + count} is greater than the length of {@code buffer}.
+     * @throws IOException
+     *             if this file is closed or another I/O error occurs.
+     * @throws NullPointerException
+     *             if {@code buffer} is {@code null}.
+     */
+    public final void readFully(byte[] buffer, int offset, int count)
+            throws IOException {
+        if (buffer == null) {
+            throw new NullPointerException();
+        }
+        // avoid int overflow
+        if (offset < 0 || offset > buffer.length || count < 0
+                || count > buffer.length - offset) {
+            throw new IndexOutOfBoundsException();
+        }
+        while (count > 0) {
+            int result = read(buffer, offset, count);
+            if (result < 0) {
+                throw new EOFException();
+            }
+            offset += result;
+            count -= result;
+        }
+    }
+
+    /**
+     * Reads a 32-bit integer from the current position in this file. Blocks
+     * until four bytes have been read, the end of the file is reached or an
+     * exception is thrown.
+     *
+     * @return the next int value from this file.
+     * @throws EOFException
+     *             if the end of this file is detected.
+     * @throws IOException
+     *             if this file is closed or another I/O error occurs.
+     */
+    public final int readInt() throws IOException {
+        byte[] buffer = new byte[4];
+        if (read(buffer, 0, buffer.length) != buffer.length) {
+            throw new EOFException();
+        }
+        return ((buffer[0] & 0xff) << 24) + ((buffer[1] & 0xff) << 16)
+                + ((buffer[2] & 0xff) << 8) + (buffer[3] & 0xff);
+    }
+
+    /**
+     * Reads a line of text form the current position in this file. A line is
+     * represented by zero or more characters followed by {@code '\n'}, {@code
+     * '\r'}, {@code "\r\n"} or the end of file marker. The string does not
+     * include the line terminating sequence.
+     * <p>
+     * Blocks until a line terminating sequence has been read, the end of the
+     * file is reached or an exception is thrown.
+     *
+     * @return the contents of the line or {@code null} if no characters have
+     *         been read before the end of the file has been reached.
+     * @throws IOException
+     *             if this file is closed or another I/O error occurs.
+     */
+    public final String readLine() throws IOException {
+        StringBuilder line = new StringBuilder(80); // Typical line length
+        boolean foundTerminator = false;
+        int unreadPosition = 0;
+        while (true) {
+            int nextByte = read();
+            switch (nextByte) {
+                case -1:
+                    return line.length() != 0 ? line.toString() : null;
+                case (byte) '\r':
+                    if (foundTerminator) {
+                        seekInternal(unreadPosition);
+                        return line.toString();
+                    }
+                    foundTerminator = true;
+                    /* Have to be able to peek ahead one byte */
+                    unreadPosition = position;
+                    break;
+                case (byte) '\n':
+                    return line.toString();
+                default:
+                    if (foundTerminator) {
+                        seekInternal(unreadPosition);
+                        return line.toString();
+                    }
+                    line.append((char) nextByte);
+            }
+        }
+    }
+
+    /**
+     * Reads a 64-bit long from the current position in this file. Blocks until
+     * eight bytes have been read, the end of the file is reached or an
+     * exception is thrown.
+     *
+     * @return the next long value from this file.
+     * @throws EOFException
+     *             if the end of this file is detected.
+     * @throws IOException
+     *             if this file is closed or another I/O error occurs.
+     */
+    public final long readLong() throws IOException {
+        byte[] buffer = new byte[8];
+        int n = read(buffer, 0, buffer.length);
+        if (n != buffer.length) {
+            throw new EOFException("expected 8 bytes; read " + n + " at final position " + position);
+        }
+        return ((long) (((buffer[0] & 0xff) << 24) + ((buffer[1] & 0xff) << 16)
+                + ((buffer[2] & 0xff) << 8) + (buffer[3] & 0xff)) << 32)
+                + ((long) (buffer[4] & 0xff) << 24)
+                + ((buffer[5] & 0xff) << 16)
+                + ((buffer[6] & 0xff) << 8)
+                + (buffer[7] & 0xff);
+    }
+
+    /**
+     * Reads a 16-bit short from the current position in this file. Blocks until
+     * two bytes have been read, the end of the file is reached or an exception
+     * is thrown.
+     *
+     * @return the next short value from this file.
+     * @throws EOFException
+     *             if the end of this file is detected.
+     * @throws IOException
+     *             if this file is closed or another I/O error occurs.
+     */
+    public final short readShort() throws IOException {
+        byte[] buffer = new byte[2];
+        if (read(buffer, 0, buffer.length) != buffer.length) {
+            throw new EOFException();
+        }
+        return (short) (((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff));
+    }
+
+    /**
+     * Reads an unsigned 8-bit byte from the current position in this file and
+     * returns it as an integer. Blocks until one byte has been read, the end of
+     * the file is reached or an exception is thrown.
+     *
+     * @return the next unsigned byte value from this file as an int.
+     * @throws EOFException
+     *             if the end of this file is detected.
+     * @throws IOException
+     *             if this file is closed or another I/O error occurs.
+     */
+    public final int readUnsignedByte() throws IOException {
+        int temp = this.read();
+        if (temp < 0) {
+            throw new EOFException();
+        }
+        return temp;
+    }
+
+    /**
+     * Reads an unsigned 16-bit short from the current position in this file and
+     * returns it as an integer. Blocks until two bytes have been read, the end of
+     * the file is reached or an exception is thrown.
+     *
+     * @return the next unsigned short value from this file as an int.
+     * @throws EOFException
+     *             if the end of this file is detected.
+     * @throws IOException
+     *             if this file is closed or another I/O error occurs.
+     */
+    public final int readUnsignedShort() throws IOException {
+        byte[] buffer = new byte[2];
+        if (read(buffer, 0, buffer.length) != buffer.length) {
+            throw new EOFException();
+        }
+        return ((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff);
+    }
+
+    /**
+     * Reads a string that is encoded in {@link DataInput modified UTF-8} from
+     * this file. The number of bytes that must be read for the complete string
+     * is determined by the first two bytes read from the file. Blocks until all
+     * required bytes have been read, the end of the file is reached or an
+     * exception is thrown.
+     *
+     * @return the next string encoded in {@link DataInput modified UTF-8} from
+     *         this file.
+     * @throws EOFException
+     *             if the end of this file is detected.
+     * @throws IOException
+     *             if this file is closed or another I/O error occurs.
+     * @throws UTFDataFormatException
+     *             if the bytes read cannot be decoded into a character string.
+     */
+    public final String readUTF() throws IOException {
+        return DataInputStream.readUTF(this);
+    }
+}

Modified: incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/net/IncomingTcpConnection.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/net/IncomingTcpConnection.java?rev=915428&r1=915421&r2=915428&view=diff
==============================================================================
--- incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/net/IncomingTcpConnection.java (original)
+++ incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/net/IncomingTcpConnection.java Tue Feb 23 16:57:51 2010
@@ -1,69 +1,69 @@
-package org.apache.cassandra.net;
-
-import java.io.*;
-import java.net.Socket;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cassandra.streaming.IncomingStreamReader;
-
-public class IncomingTcpConnection extends Thread
-{
-    private static Logger logger = Logger.getLogger(IncomingTcpConnection.class);
-
-    private final DataInputStream input;
-    private Socket socket;
-
-    public IncomingTcpConnection(Socket socket)
-    {
-        this.socket = socket;
-        try
-        {
-            input = new DataInputStream(socket.getInputStream());
-        }
-        catch (IOException e)
-        {
-            throw new IOError(e);
-        }
-    }
-
-    @Override
-    public void run()
-    {
-        while (true)
-        {
-            try
-            {
-                MessagingService.validateMagic(input.readInt());
-                int header = input.readInt();
-                int type = MessagingService.getBits(header, 1, 2);
-                boolean isStream = MessagingService.getBits(header, 3, 1) == 1;
-                int version = MessagingService.getBits(header, 15, 8);
-
-                if (isStream)
-                {
-                    new IncomingStreamReader(socket.getChannel()).read();
-                }
-                else
-                {
-                    int size = input.readInt();
-                    byte[] contentBytes = new byte[size];
-                    input.readFully(contentBytes);
-                    MessagingService.getDeserializationExecutor().submit(new MessageDeserializationTask(new ByteArrayInputStream(contentBytes)));
-                }
-            }
-            catch (EOFException e)
-            {
-                if (logger.isTraceEnabled())
-                    logger.trace("eof reading from socket; closing", e);
-                break;
-            }
-            catch (IOException e)
-            {
-                if (logger.isDebugEnabled())
-                    logger.debug("error reading from socket; closing", e);
-                break;
-            }
-        }
-    }
-}
+package org.apache.cassandra.net;
+
+import java.io.*;
+import java.net.Socket;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cassandra.streaming.IncomingStreamReader;
+
+public class IncomingTcpConnection extends Thread
+{
+    private static Logger logger = Logger.getLogger(IncomingTcpConnection.class);
+
+    private final DataInputStream input;
+    private Socket socket;
+
+    public IncomingTcpConnection(Socket socket)
+    {
+        this.socket = socket;
+        try
+        {
+            input = new DataInputStream(socket.getInputStream());
+        }
+        catch (IOException e)
+        {
+            throw new IOError(e);
+        }
+    }
+
+    @Override
+    public void run()
+    {
+        while (true)
+        {
+            try
+            {
+                MessagingService.validateMagic(input.readInt());
+                int header = input.readInt();
+                int type = MessagingService.getBits(header, 1, 2);
+                boolean isStream = MessagingService.getBits(header, 3, 1) == 1;
+                int version = MessagingService.getBits(header, 15, 8);
+
+                if (isStream)
+                {
+                    new IncomingStreamReader(socket.getChannel()).read();
+                }
+                else
+                {
+                    int size = input.readInt();
+                    byte[] contentBytes = new byte[size];
+                    input.readFully(contentBytes);
+                    MessagingService.getDeserializationExecutor().submit(new MessageDeserializationTask(new ByteArrayInputStream(contentBytes)));
+                }
+            }
+            catch (EOFException e)
+            {
+                if (logger.isTraceEnabled())
+                    logger.trace("eof reading from socket; closing", e);
+                break;
+            }
+            catch (IOException e)
+            {
+                if (logger.isDebugEnabled())
+                    logger.debug("error reading from socket; closing", e);
+                break;
+            }
+        }
+    }
+}

Modified: incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/CompletedFileStatus.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/CompletedFileStatus.java?rev=915428&r1=915421&r2=915428&view=diff
==============================================================================
--- incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/CompletedFileStatus.java (original)
+++ incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/CompletedFileStatus.java Tue Feb 23 16:57:51 2010
@@ -1,100 +1,100 @@
-package org.apache.cassandra.streaming;
-
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-import org.apache.cassandra.io.ICompactSerializer;
-import org.apache.cassandra.net.Message;
-import org.apache.cassandra.service.StorageService;
-import org.apache.cassandra.utils.FBUtilities;
-
-class CompletedFileStatus
-{
-    private static ICompactSerializer<CompletedFileStatus> serializer_;
-
-    public static enum StreamCompletionAction
-    {
-        DELETE,
-        STREAM
-    }
-
-    static
-    {
-        serializer_ = new CompletedFileStatusSerializer();
-    }
-
-    public static ICompactSerializer<CompletedFileStatus> serializer()
-    {
-        return serializer_;
-    }
-
-    private String file_;
-    private long expectedBytes_;
-    private StreamCompletionAction action_;
-
-    public CompletedFileStatus(String file, long expectedBytes)
-    {
-        file_ = file;
-        expectedBytes_ = expectedBytes;
-        action_ = StreamCompletionAction.DELETE;
-    }
-
-    public String getFile()
-    {
-        return file_;
-    }
-
-    public long getExpectedBytes()
-    {
-        return expectedBytes_;
-    }
-
-    public void setAction(StreamCompletionAction action)
-    {
-        action_ = action;
-    }
-
-    public StreamCompletionAction getAction()
-    {
-        return action_;
-    }
-
-    public Message makeStreamStatusMessage() throws IOException
-    {
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        DataOutputStream dos = new DataOutputStream( bos );
-        CompletedFileStatus.serializer().serialize(this, dos);
-        return new Message(FBUtilities.getLocalAddress(), "", StorageService.Verb.STREAM_FINISHED, bos.toByteArray());
-    }
-
-    private static class CompletedFileStatusSerializer implements ICompactSerializer<CompletedFileStatus>
-    {
-        public void serialize(CompletedFileStatus streamStatus, DataOutputStream dos) throws IOException
-        {
-            dos.writeUTF(streamStatus.getFile());
-            dos.writeLong(streamStatus.getExpectedBytes());
-            dos.writeInt(streamStatus.getAction().ordinal());
-        }
-
-        public CompletedFileStatus deserialize(DataInputStream dis) throws IOException
-        {
-            String targetFile = dis.readUTF();
-            long expectedBytes = dis.readLong();
-            CompletedFileStatus streamStatus = new CompletedFileStatus(targetFile, expectedBytes);
-
-            int ordinal = dis.readInt();
-            if ( ordinal == StreamCompletionAction.DELETE.ordinal() )
-            {
-                streamStatus.setAction(StreamCompletionAction.DELETE);
-            }
-            else if ( ordinal == StreamCompletionAction.STREAM.ordinal() )
-            {
-                streamStatus.setAction(StreamCompletionAction.STREAM);
-            }
-
-            return streamStatus;
-        }
-    }
-}
+package org.apache.cassandra.streaming;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.cassandra.io.ICompactSerializer;
+import org.apache.cassandra.net.Message;
+import org.apache.cassandra.service.StorageService;
+import org.apache.cassandra.utils.FBUtilities;
+
+class CompletedFileStatus
+{
+    private static ICompactSerializer<CompletedFileStatus> serializer_;
+
+    public static enum StreamCompletionAction
+    {
+        DELETE,
+        STREAM
+    }
+
+    static
+    {
+        serializer_ = new CompletedFileStatusSerializer();
+    }
+
+    public static ICompactSerializer<CompletedFileStatus> serializer()
+    {
+        return serializer_;
+    }
+
+    private String file_;
+    private long expectedBytes_;
+    private StreamCompletionAction action_;
+
+    public CompletedFileStatus(String file, long expectedBytes)
+    {
+        file_ = file;
+        expectedBytes_ = expectedBytes;
+        action_ = StreamCompletionAction.DELETE;
+    }
+
+    public String getFile()
+    {
+        return file_;
+    }
+
+    public long getExpectedBytes()
+    {
+        return expectedBytes_;
+    }
+
+    public void setAction(StreamCompletionAction action)
+    {
+        action_ = action;
+    }
+
+    public StreamCompletionAction getAction()
+    {
+        return action_;
+    }
+
+    public Message makeStreamStatusMessage() throws IOException
+    {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        DataOutputStream dos = new DataOutputStream( bos );
+        CompletedFileStatus.serializer().serialize(this, dos);
+        return new Message(FBUtilities.getLocalAddress(), "", StorageService.Verb.STREAM_FINISHED, bos.toByteArray());
+    }
+
+    private static class CompletedFileStatusSerializer implements ICompactSerializer<CompletedFileStatus>
+    {
+        public void serialize(CompletedFileStatus streamStatus, DataOutputStream dos) throws IOException
+        {
+            dos.writeUTF(streamStatus.getFile());
+            dos.writeLong(streamStatus.getExpectedBytes());
+            dos.writeInt(streamStatus.getAction().ordinal());
+        }
+
+        public CompletedFileStatus deserialize(DataInputStream dis) throws IOException
+        {
+            String targetFile = dis.readUTF();
+            long expectedBytes = dis.readLong();
+            CompletedFileStatus streamStatus = new CompletedFileStatus(targetFile, expectedBytes);
+
+            int ordinal = dis.readInt();
+            if ( ordinal == StreamCompletionAction.DELETE.ordinal() )
+            {
+                streamStatus.setAction(StreamCompletionAction.DELETE);
+            }
+            else if ( ordinal == StreamCompletionAction.STREAM.ordinal() )
+            {
+                streamStatus.setAction(StreamCompletionAction.STREAM);
+            }
+
+            return streamStatus;
+        }
+    }
+}

Modified: incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamCompletionHandler.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamCompletionHandler.java?rev=915428&r1=915421&r2=915428&view=diff
==============================================================================
--- incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamCompletionHandler.java (original)
+++ incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamCompletionHandler.java Tue Feb 23 16:57:51 2010
@@ -1,62 +1,62 @@
-package org.apache.cassandra.streaming;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.InetAddress;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cassandra.db.Table;
-import org.apache.cassandra.io.SSTableReader;
-import org.apache.cassandra.io.SSTableWriter;
-import org.apache.cassandra.net.MessagingService;
-import org.apache.cassandra.streaming.IStreamComplete;
-import org.apache.cassandra.streaming.StreamInManager;
-import org.apache.cassandra.service.StorageService;
-
-/**
- * This is the callback handler that is invoked when we have
- * completely received a single file from a remote host.
- *
- * TODO if we move this into CFS we could make addSSTables private, improving encapsulation.
-*/
-class StreamCompletionHandler implements IStreamComplete
-{
-    private static Logger logger = Logger.getLogger(StreamCompletionHandler.class);
-
-    public void onStreamCompletion(InetAddress host, PendingFile pendingFile, CompletedFileStatus streamStatus) throws IOException
-    {
-        /* Parse the stream context and the file to the list of SSTables in the associated Column Family Store. */
-        if (pendingFile.getTargetFile().contains("-Data.db"))
-        {
-            String tableName = pendingFile.getTable();
-            File file = new File( pendingFile.getTargetFile() );
-            String fileName = file.getName();
-            String [] temp = fileName.split("-");
-
-            //Open the file to see if all parts are now here
-            try
-            {
-                SSTableReader sstable = SSTableWriter.renameAndOpen(pendingFile.getTargetFile());
-                //TODO add a sanity check that this sstable has all its parts and is ok
-                Table.open(tableName).getColumnFamilyStore(temp[0]).addSSTable(sstable);
-                logger.info("Streaming added " + sstable.getFilename());
-            }
-            catch (IOException e)
-            {
-                throw new RuntimeException("Not able to add streamed file " + pendingFile.getTargetFile(), e);
-            }
-        }
-
-        if (logger.isDebugEnabled())
-          logger.debug("Sending a streaming finished message with " + streamStatus + " to " + host);
-        /* Send a StreamStatus message which may require the source node to re-stream certain files. */
-        MessagingService.instance.sendOneWay(streamStatus.makeStreamStatusMessage(), host);
-
-        /* If we're done with everything for this host, remove from bootstrap sources */
-        if (StreamInManager.isDone(host) && StorageService.instance.isBootstrapMode())
-        {
-            StorageService.instance.removeBootstrapSource(host, pendingFile.getTable());
-        }
-    }
-}
+package org.apache.cassandra.streaming;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cassandra.db.Table;
+import org.apache.cassandra.io.SSTableReader;
+import org.apache.cassandra.io.SSTableWriter;
+import org.apache.cassandra.net.MessagingService;
+import org.apache.cassandra.streaming.IStreamComplete;
+import org.apache.cassandra.streaming.StreamInManager;
+import org.apache.cassandra.service.StorageService;
+
+/**
+ * This is the callback handler that is invoked when we have
+ * completely received a single file from a remote host.
+ *
+ * TODO if we move this into CFS we could make addSSTables private, improving encapsulation.
+*/
+class StreamCompletionHandler implements IStreamComplete
+{
+    private static Logger logger = Logger.getLogger(StreamCompletionHandler.class);
+
+    public void onStreamCompletion(InetAddress host, PendingFile pendingFile, CompletedFileStatus streamStatus) throws IOException
+    {
+        /* Parse the stream context and the file to the list of SSTables in the associated Column Family Store. */
+        if (pendingFile.getTargetFile().contains("-Data.db"))
+        {
+            String tableName = pendingFile.getTable();
+            File file = new File( pendingFile.getTargetFile() );
+            String fileName = file.getName();
+            String [] temp = fileName.split("-");
+
+            //Open the file to see if all parts are now here
+            try
+            {
+                SSTableReader sstable = SSTableWriter.renameAndOpen(pendingFile.getTargetFile());
+                //TODO add a sanity check that this sstable has all its parts and is ok
+                Table.open(tableName).getColumnFamilyStore(temp[0]).addSSTable(sstable);
+                logger.info("Streaming added " + sstable.getFilename());
+            }
+            catch (IOException e)
+            {
+                throw new RuntimeException("Not able to add streamed file " + pendingFile.getTargetFile(), e);
+            }
+        }
+
+        if (logger.isDebugEnabled())
+          logger.debug("Sending a streaming finished message with " + streamStatus + " to " + host);
+        /* Send a StreamStatus message which may require the source node to re-stream certain files. */
+        MessagingService.instance.sendOneWay(streamStatus.makeStreamStatusMessage(), host);
+
+        /* If we're done with everything for this host, remove from bootstrap sources */
+        if (StreamInManager.isDone(host) && StorageService.instance.isBootstrapMode())
+        {
+            StorageService.instance.removeBootstrapSource(host, pendingFile.getTable());
+        }
+    }
+}

Modified: incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamFinishedVerbHandler.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamFinishedVerbHandler.java?rev=915428&r1=915421&r2=915428&view=diff
==============================================================================
--- incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamFinishedVerbHandler.java (original)
+++ incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamFinishedVerbHandler.java Tue Feb 23 16:57:51 2010
@@ -1,48 +1,48 @@
-package org.apache.cassandra.streaming;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.IOError;
-import java.io.IOException;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cassandra.net.IVerbHandler;
-import org.apache.cassandra.net.Message;
-import org.apache.cassandra.streaming.StreamOutManager;
-
-public class StreamFinishedVerbHandler implements IVerbHandler
-{
-    private static Logger logger = Logger.getLogger(StreamFinishedVerbHandler.class);
-
-    public void doVerb(Message message)
-    {
-        byte[] body = message.getMessageBody();
-        ByteArrayInputStream bufIn = new ByteArrayInputStream(body);
-
-        try
-        {
-            CompletedFileStatus streamStatus = CompletedFileStatus.serializer().deserialize(new DataInputStream(bufIn));
-
-            switch (streamStatus.getAction())
-            {
-                case DELETE:
-                    StreamOutManager.get(message.getFrom()).finishAndStartNext(streamStatus.getFile());
-                    break;
-
-                case STREAM:
-                    if (logger.isDebugEnabled())
-                        logger.debug("Need to re-stream file " + streamStatus.getFile());
-                    StreamOutManager.get(message.getFrom()).startNext();
-                    break;
-
-                default:
-                    break;
-            }
-        }
-        catch (IOException ex)
-        {
-            throw new IOError(ex);
-        }
-    }
-}
+package org.apache.cassandra.streaming;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOError;
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cassandra.net.IVerbHandler;
+import org.apache.cassandra.net.Message;
+import org.apache.cassandra.streaming.StreamOutManager;
+
+public class StreamFinishedVerbHandler implements IVerbHandler
+{
+    private static Logger logger = Logger.getLogger(StreamFinishedVerbHandler.class);
+
+    public void doVerb(Message message)
+    {
+        byte[] body = message.getMessageBody();
+        ByteArrayInputStream bufIn = new ByteArrayInputStream(body);
+
+        try
+        {
+            CompletedFileStatus streamStatus = CompletedFileStatus.serializer().deserialize(new DataInputStream(bufIn));
+
+            switch (streamStatus.getAction())
+            {
+                case DELETE:
+                    StreamOutManager.get(message.getFrom()).finishAndStartNext(streamStatus.getFile());
+                    break;
+
+                case STREAM:
+                    if (logger.isDebugEnabled())
+                        logger.debug("Need to re-stream file " + streamStatus.getFile());
+                    StreamOutManager.get(message.getFrom()).startNext();
+                    break;
+
+                default:
+                    break;
+            }
+        }
+        catch (IOException ex)
+        {
+            throw new IOError(ex);
+        }
+    }
+}

Modified: incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamInitiateDoneVerbHandler.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamInitiateDoneVerbHandler.java?rev=915428&r1=915421&r2=915428&view=diff
==============================================================================
--- incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamInitiateDoneVerbHandler.java (original)
+++ incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamInitiateDoneVerbHandler.java Tue Feb 23 16:57:51 2010
@@ -1,19 +1,19 @@
-package org.apache.cassandra.streaming;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cassandra.net.IVerbHandler;
-import org.apache.cassandra.net.Message;
-import org.apache.cassandra.streaming.StreamOutManager;
-
-public class StreamInitiateDoneVerbHandler implements IVerbHandler
-{
-    private static Logger logger = Logger.getLogger(StreamInitiateDoneVerbHandler.class);
-
-    public void doVerb(Message message)
-    {
-        if (logger.isDebugEnabled())
-          logger.debug("Received a stream initiate done message ...");
-        StreamOutManager.get(message.getFrom()).startNext();
-    }
-}
+package org.apache.cassandra.streaming;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cassandra.net.IVerbHandler;
+import org.apache.cassandra.net.Message;
+import org.apache.cassandra.streaming.StreamOutManager;
+
+public class StreamInitiateDoneVerbHandler implements IVerbHandler
+{
+    private static Logger logger = Logger.getLogger(StreamInitiateDoneVerbHandler.class);
+
+    public void doVerb(Message message)
+    {
+        if (logger.isDebugEnabled())
+          logger.debug("Received a stream initiate done message ...");
+        StreamOutManager.get(message.getFrom()).startNext();
+    }
+}

Modified: incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamInitiateVerbHandler.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamInitiateVerbHandler.java?rev=915428&r1=915421&r2=915428&view=diff
==============================================================================
--- incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamInitiateVerbHandler.java (original)
+++ incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamInitiateVerbHandler.java Tue Feb 23 16:57:51 2010
@@ -1,145 +1,145 @@
-package org.apache.cassandra.streaming;
-
-import java.io.*;
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cassandra.config.DatabaseDescriptor;
-import org.apache.cassandra.db.ColumnFamilyStore;
-import org.apache.cassandra.db.Table;
-import org.apache.cassandra.streaming.StreamInitiateMessage;
-import org.apache.cassandra.net.IVerbHandler;
-import org.apache.cassandra.net.Message;
-import org.apache.cassandra.net.MessagingService;
-import org.apache.cassandra.streaming.StreamInManager;
-import org.apache.cassandra.service.StorageService;
-import org.apache.cassandra.utils.FBUtilities;
-
-public class StreamInitiateVerbHandler implements IVerbHandler
-{
-    private static Logger logger = Logger.getLogger(StreamInitiateVerbHandler.class);
-
-    /*
-     * Here we handle the StreamInitiateMessage. Here we get the
-     * array of StreamContexts. We get file names for the column
-     * families associated with the files and replace them with the
-     * file names as obtained from the column family store on the
-     * receiving end.
-    */
-    public void doVerb(Message message)
-    {
-        byte[] body = message.getMessageBody();
-        ByteArrayInputStream bufIn = new ByteArrayInputStream(body);
-        if (logger.isDebugEnabled())
-            logger.debug(String.format("StreamInitiateVerbeHandler.doVerb %s %s %s", message.getVerb(), message.getMessageId(), message.getMessageType()));
-
-        try
-        {
-            StreamInitiateMessage biMsg = StreamInitiateMessage.serializer().deserialize(new DataInputStream(bufIn));
-            PendingFile[] pendingFiles = biMsg.getStreamContext();
-
-            if (pendingFiles.length == 0)
-            {
-                if (logger.isDebugEnabled())
-                    logger.debug("no data needed from " + message.getFrom());
-                if (StorageService.instance.isBootstrapMode())
-                    StorageService.instance.removeBootstrapSource(message.getFrom(), new String(message.getHeader(StreamOut.TABLE_NAME)));
-                return;
-            }
-
-            Map<String, String> fileNames = getNewNames(pendingFiles);
-            Map<String, String> pathNames = new HashMap<String, String>();
-            for (String ssName : fileNames.keySet())
-                pathNames.put(ssName, DatabaseDescriptor.getNextAvailableDataLocation());
-            /*
-             * For each of stream context's in the incoming message
-             * generate the new file names and store the new file names
-             * in the StreamContextManager.
-            */
-            for (PendingFile pendingFile : pendingFiles)
-            {
-                CompletedFileStatus streamStatus = new CompletedFileStatus(pendingFile.getTargetFile(), pendingFile.getExpectedBytes() );
-                String file = getNewFileNameFromOldContextAndNames(fileNames, pathNames, pendingFile);
-
-                if (logger.isDebugEnabled())
-                  logger.debug("Received Data from  : " + message.getFrom() + " " + pendingFile.getTargetFile() + " " + file);
-                pendingFile.setTargetFile(file);
-                addStreamContext(message.getFrom(), pendingFile, streamStatus);
-            }
-
-            StreamInManager.registerStreamCompletionHandler(message.getFrom(), new StreamCompletionHandler());
-            if (logger.isDebugEnabled())
-              logger.debug("Sending a stream initiate done message ...");
-            Message doneMessage = new Message(FBUtilities.getLocalAddress(), "", StorageService.Verb.STREAM_INITIATE_DONE, new byte[0] );
-            MessagingService.instance.sendOneWay(doneMessage, message.getFrom());
-        }
-        catch (IOException ex)
-        {
-            throw new IOError(ex);
-        }
-    }
-
-    public String getNewFileNameFromOldContextAndNames(Map<String, String> fileNames,
-                                                       Map<String, String> pathNames,
-                                                       PendingFile pendingFile)
-    {
-        File sourceFile = new File( pendingFile.getTargetFile() );
-        String[] piece = FBUtilities.strip(sourceFile.getName(), "-");
-        String cfName = piece[0];
-        String ssTableNum = piece[1];
-        String typeOfFile = piece[2];
-
-        String newFileNameExpanded = fileNames.get(pendingFile.getTable() + "-" + cfName + "-" + ssTableNum);
-        String path = pathNames.get(pendingFile.getTable() + "-" + cfName + "-" + ssTableNum);
-        //Drop type (Data.db) from new FileName
-        String newFileName = newFileNameExpanded.replace("Data.db", typeOfFile);
-        return path + File.separator + pendingFile.getTable() + File.separator + newFileName;
-    }
-
-    // todo: this method needs to be private, or package at the very least for easy unit testing.
-    public Map<String, String> getNewNames(PendingFile[] pendingFiles) throws IOException
-    {
-        /*
-         * Mapping for each file with unique CF-i ---> new file name. For eg.
-         * for a file with name <CF>-<i>-Data.db there is a corresponding
-         * <CF>-<i>-Index.db. We maintain a mapping from <CF>-<i> to a newly
-         * generated file name.
-        */
-        Map<String, String> fileNames = new HashMap<String, String>();
-        /* Get the distinct entries from StreamContexts i.e have one entry per Data/Index/Filter file set */
-        Set<String> distinctEntries = new HashSet<String>();
-        for ( PendingFile pendingFile : pendingFiles)
-        {
-            String[] pieces = FBUtilities.strip(new File(pendingFile.getTargetFile()).getName(), "-");
-            distinctEntries.add(pendingFile.getTable() + "-" + pieces[0] + "-" + pieces[1] );
-        }
-
-        /* Generate unique file names per entry */
-        for ( String distinctEntry : distinctEntries )
-        {
-            String tableName;
-            String[] pieces = FBUtilities.strip(distinctEntry, "-");
-            tableName = pieces[0];
-            Table table = Table.open( tableName );
-
-            ColumnFamilyStore cfStore = table.getColumnFamilyStore(pieces[1]);
-            if (logger.isDebugEnabled())
-              logger.debug("Generating file name for " + distinctEntry + " ...");
-            fileNames.put(distinctEntry, cfStore.getTempSSTableFileName());
-        }
-
-        return fileNames;
-    }
-
-    private void addStreamContext(InetAddress host, PendingFile pendingFile, CompletedFileStatus streamStatus)
-    {
-        if (logger.isDebugEnabled())
-          logger.debug("Adding stream context " + pendingFile + " for " + host + " ...");
-        StreamInManager.addStreamContext(host, pendingFile, streamStatus);
-    }
-}
+package org.apache.cassandra.streaming;
+
+import java.io.*;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.db.ColumnFamilyStore;
+import org.apache.cassandra.db.Table;
+import org.apache.cassandra.streaming.StreamInitiateMessage;
+import org.apache.cassandra.net.IVerbHandler;
+import org.apache.cassandra.net.Message;
+import org.apache.cassandra.net.MessagingService;
+import org.apache.cassandra.streaming.StreamInManager;
+import org.apache.cassandra.service.StorageService;
+import org.apache.cassandra.utils.FBUtilities;
+
+public class StreamInitiateVerbHandler implements IVerbHandler
+{
+    private static Logger logger = Logger.getLogger(StreamInitiateVerbHandler.class);
+
+    /*
+     * Here we handle the StreamInitiateMessage. Here we get the
+     * array of StreamContexts. We get file names for the column
+     * families associated with the files and replace them with the
+     * file names as obtained from the column family store on the
+     * receiving end.
+    */
+    public void doVerb(Message message)
+    {
+        byte[] body = message.getMessageBody();
+        ByteArrayInputStream bufIn = new ByteArrayInputStream(body);
+        if (logger.isDebugEnabled())
+            logger.debug(String.format("StreamInitiateVerbeHandler.doVerb %s %s %s", message.getVerb(), message.getMessageId(), message.getMessageType()));
+
+        try
+        {
+            StreamInitiateMessage biMsg = StreamInitiateMessage.serializer().deserialize(new DataInputStream(bufIn));
+            PendingFile[] pendingFiles = biMsg.getStreamContext();
+
+            if (pendingFiles.length == 0)
+            {
+                if (logger.isDebugEnabled())
+                    logger.debug("no data needed from " + message.getFrom());
+                if (StorageService.instance.isBootstrapMode())
+                    StorageService.instance.removeBootstrapSource(message.getFrom(), new String(message.getHeader(StreamOut.TABLE_NAME)));
+                return;
+            }
+
+            Map<String, String> fileNames = getNewNames(pendingFiles);
+            Map<String, String> pathNames = new HashMap<String, String>();
+            for (String ssName : fileNames.keySet())
+                pathNames.put(ssName, DatabaseDescriptor.getNextAvailableDataLocation());
+            /*
+             * For each of stream context's in the incoming message
+             * generate the new file names and store the new file names
+             * in the StreamContextManager.
+            */
+            for (PendingFile pendingFile : pendingFiles)
+            {
+                CompletedFileStatus streamStatus = new CompletedFileStatus(pendingFile.getTargetFile(), pendingFile.getExpectedBytes() );
+                String file = getNewFileNameFromOldContextAndNames(fileNames, pathNames, pendingFile);
+
+                if (logger.isDebugEnabled())
+                  logger.debug("Received Data from  : " + message.getFrom() + " " + pendingFile.getTargetFile() + " " + file);
+                pendingFile.setTargetFile(file);
+                addStreamContext(message.getFrom(), pendingFile, streamStatus);
+            }
+
+            StreamInManager.registerStreamCompletionHandler(message.getFrom(), new StreamCompletionHandler());
+            if (logger.isDebugEnabled())
+              logger.debug("Sending a stream initiate done message ...");
+            Message doneMessage = new Message(FBUtilities.getLocalAddress(), "", StorageService.Verb.STREAM_INITIATE_DONE, new byte[0] );
+            MessagingService.instance.sendOneWay(doneMessage, message.getFrom());
+        }
+        catch (IOException ex)
+        {
+            throw new IOError(ex);
+        }
+    }
+
+    public String getNewFileNameFromOldContextAndNames(Map<String, String> fileNames,
+                                                       Map<String, String> pathNames,
+                                                       PendingFile pendingFile)
+    {
+        File sourceFile = new File( pendingFile.getTargetFile() );
+        String[] piece = FBUtilities.strip(sourceFile.getName(), "-");
+        String cfName = piece[0];
+        String ssTableNum = piece[1];
+        String typeOfFile = piece[2];
+
+        String newFileNameExpanded = fileNames.get(pendingFile.getTable() + "-" + cfName + "-" + ssTableNum);
+        String path = pathNames.get(pendingFile.getTable() + "-" + cfName + "-" + ssTableNum);
+        //Drop type (Data.db) from new FileName
+        String newFileName = newFileNameExpanded.replace("Data.db", typeOfFile);
+        return path + File.separator + pendingFile.getTable() + File.separator + newFileName;
+    }
+
+    // todo: this method needs to be private, or package at the very least for easy unit testing.
+    public Map<String, String> getNewNames(PendingFile[] pendingFiles) throws IOException
+    {
+        /*
+         * Mapping for each file with unique CF-i ---> new file name. For eg.
+         * for a file with name <CF>-<i>-Data.db there is a corresponding
+         * <CF>-<i>-Index.db. We maintain a mapping from <CF>-<i> to a newly
+         * generated file name.
+        */
+        Map<String, String> fileNames = new HashMap<String, String>();
+        /* Get the distinct entries from StreamContexts i.e have one entry per Data/Index/Filter file set */
+        Set<String> distinctEntries = new HashSet<String>();
+        for ( PendingFile pendingFile : pendingFiles)
+        {
+            String[] pieces = FBUtilities.strip(new File(pendingFile.getTargetFile()).getName(), "-");
+            distinctEntries.add(pendingFile.getTable() + "-" + pieces[0] + "-" + pieces[1] );
+        }
+
+        /* Generate unique file names per entry */
+        for ( String distinctEntry : distinctEntries )
+        {
+            String tableName;
+            String[] pieces = FBUtilities.strip(distinctEntry, "-");
+            tableName = pieces[0];
+            Table table = Table.open( tableName );
+
+            ColumnFamilyStore cfStore = table.getColumnFamilyStore(pieces[1]);
+            if (logger.isDebugEnabled())
+              logger.debug("Generating file name for " + distinctEntry + " ...");
+            fileNames.put(distinctEntry, cfStore.getTempSSTableFileName());
+        }
+
+        return fileNames;
+    }
+
+    private void addStreamContext(InetAddress host, PendingFile pendingFile, CompletedFileStatus streamStatus)
+    {
+        if (logger.isDebugEnabled())
+          logger.debug("Adding stream context " + pendingFile + " for " + host + " ...");
+        StreamInManager.addStreamContext(host, pendingFile, streamStatus);
+    }
+}

Modified: incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamRequestMessage.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamRequestMessage.java?rev=915428&r1=915421&r2=915428&view=diff
==============================================================================
--- incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamRequestMessage.java (original)
+++ incubator/cassandra/tags/cassandra-0.6.0-beta1/src/java/org/apache/cassandra/streaming/StreamRequestMessage.java Tue Feb 23 16:57:51 2010
@@ -1,76 +1,76 @@
-package org.apache.cassandra.streaming;
-
-import java.io.*;
-
-import org.apache.cassandra.concurrent.StageManager;
-import org.apache.cassandra.io.ICompactSerializer;
-import org.apache.cassandra.net.Message;
-import org.apache.cassandra.service.StorageService;
-import org.apache.cassandra.utils.FBUtilities;
-
-/**
-* This class encapsulates the message that needs to be sent to nodes
-* that handoff data. The message contains information about ranges
-* that need to be transferred and the target node.
-*/
-class StreamRequestMessage
-{
-   private static ICompactSerializer<StreamRequestMessage> serializer_;
-   static
-   {
-       serializer_ = new StreamRequestMessageSerializer();
-   }
-
-   protected static ICompactSerializer<StreamRequestMessage> serializer()
-   {
-       return serializer_;
-   }
-
-   protected static Message makeStreamRequestMessage(StreamRequestMessage streamRequestMessage)
-   {
-       ByteArrayOutputStream bos = new ByteArrayOutputStream();
-       DataOutputStream dos = new DataOutputStream(bos);
-       try
-       {
-           StreamRequestMessage.serializer().serialize(streamRequestMessage, dos);
-       }
-       catch (IOException e)
-       {
-           throw new IOError(e);
-       }
-       return new Message(FBUtilities.getLocalAddress(), StageManager.STREAM_STAGE, StorageService.Verb.STREAM_REQUEST, bos.toByteArray() );
-   }
-
-   protected StreamRequestMetadata[] streamRequestMetadata_ = new StreamRequestMetadata[0];
-
-   // TODO only actually ever need one BM, not an array
-   StreamRequestMessage(StreamRequestMetadata... streamRequestMetadata)
-   {
-       assert streamRequestMetadata != null;
-       streamRequestMetadata_ = streamRequestMetadata;
-   }
-
-    private static class StreamRequestMessageSerializer implements ICompactSerializer<StreamRequestMessage>
-    {
-        public void serialize(StreamRequestMessage streamRequestMessage, DataOutputStream dos) throws IOException
-        {
-            StreamRequestMetadata[] streamRequestMetadata = streamRequestMessage.streamRequestMetadata_;
-            dos.writeInt(streamRequestMetadata.length);
-            for (StreamRequestMetadata bsmd : streamRequestMetadata)
-            {
-                StreamRequestMetadata.serializer().serialize(bsmd, dos);
-            }
-        }
-
-        public StreamRequestMessage deserialize(DataInputStream dis) throws IOException
-        {
-            int size = dis.readInt();
-            StreamRequestMetadata[] streamRequestMetadata = new StreamRequestMetadata[size];
-            for (int i = 0; i < size; ++i)
-            {
-                streamRequestMetadata[i] = StreamRequestMetadata.serializer().deserialize(dis);
-            }
-            return new StreamRequestMessage(streamRequestMetadata);
-        }
-    }
-}
+package org.apache.cassandra.streaming;
+
+import java.io.*;
+
+import org.apache.cassandra.concurrent.StageManager;
+import org.apache.cassandra.io.ICompactSerializer;
+import org.apache.cassandra.net.Message;
+import org.apache.cassandra.service.StorageService;
+import org.apache.cassandra.utils.FBUtilities;
+
+/**
+* This class encapsulates the message that needs to be sent to nodes
+* that handoff data. The message contains information about ranges
+* that need to be transferred and the target node.
+*/
+class StreamRequestMessage
+{
+   private static ICompactSerializer<StreamRequestMessage> serializer_;
+   static
+   {
+       serializer_ = new StreamRequestMessageSerializer();
+   }
+
+   protected static ICompactSerializer<StreamRequestMessage> serializer()
+   {
+       return serializer_;
+   }
+
+   protected static Message makeStreamRequestMessage(StreamRequestMessage streamRequestMessage)
+   {
+       ByteArrayOutputStream bos = new ByteArrayOutputStream();
+       DataOutputStream dos = new DataOutputStream(bos);
+       try
+       {
+           StreamRequestMessage.serializer().serialize(streamRequestMessage, dos);
+       }
+       catch (IOException e)
+       {
+           throw new IOError(e);
+       }
+       return new Message(FBUtilities.getLocalAddress(), StageManager.STREAM_STAGE, StorageService.Verb.STREAM_REQUEST, bos.toByteArray() );
+   }
+
+   protected StreamRequestMetadata[] streamRequestMetadata_ = new StreamRequestMetadata[0];
+
+   // TODO only actually ever need one BM, not an array
+   StreamRequestMessage(StreamRequestMetadata... streamRequestMetadata)
+   {
+       assert streamRequestMetadata != null;
+       streamRequestMetadata_ = streamRequestMetadata;
+   }
+
+    private static class StreamRequestMessageSerializer implements ICompactSerializer<StreamRequestMessage>
+    {
+        public void serialize(StreamRequestMessage streamRequestMessage, DataOutputStream dos) throws IOException
+        {
+            StreamRequestMetadata[] streamRequestMetadata = streamRequestMessage.streamRequestMetadata_;
+            dos.writeInt(streamRequestMetadata.length);
+            for (StreamRequestMetadata bsmd : streamRequestMetadata)
+            {
+                StreamRequestMetadata.serializer().serialize(bsmd, dos);
+            }
+        }
+
+        public StreamRequestMessage deserialize(DataInputStream dis) throws IOException
+        {
+            int size = dis.readInt();
+            StreamRequestMetadata[] streamRequestMetadata = new StreamRequestMetadata[size];
+            for (int i = 0; i < size; ++i)
+            {
+                streamRequestMetadata[i] = StreamRequestMetadata.serializer().deserialize(dis);
+            }
+            return new StreamRequestMessage(streamRequestMetadata);
+        }
+    }
+}

Modified: incubator/cassandra/tags/cassandra-0.6.0-beta1/test/unit/org/apache/cassandra/dht/BoundsTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/tags/cassandra-0.6.0-beta1/test/unit/org/apache/cassandra/dht/BoundsTest.java?rev=915428&r1=915421&r2=915428&view=diff
==============================================================================
--- incubator/cassandra/tags/cassandra-0.6.0-beta1/test/unit/org/apache/cassandra/dht/BoundsTest.java (original)
+++ incubator/cassandra/tags/cassandra-0.6.0-beta1/test/unit/org/apache/cassandra/dht/BoundsTest.java Tue Feb 23 16:57:51 2010
@@ -1,73 +1,73 @@
-package org.apache.cassandra.dht;
-
-import java.util.*;
-
-import junit.framework.TestCase;
-import org.apache.cassandra.utils.FBUtilities;
-
-public class BoundsTest extends TestCase
-{
-    public void testRestrictTo() throws Exception
-    {
-        IPartitioner p = new OrderPreservingPartitioner();
-        Token min = p.getMinimumToken();
-        Range wraps = new Range(new StringToken("m"), new StringToken("e"));
-        Range normal = new Range(wraps.right, wraps.left);
-        Bounds all = new Bounds(min, min, p);
-        Bounds almostAll = new Bounds(new StringToken("a"), min, p);
-
-        Set<AbstractBounds> S;
-        Set<AbstractBounds> S2;
-
-        S = all.restrictTo(wraps);
-        assert S.equals(new HashSet<AbstractBounds>(Arrays.asList(wraps)));
-
-        S = almostAll.restrictTo(wraps);
-        S2 = new HashSet<AbstractBounds>(Arrays.asList(new Bounds(new StringToken("a"), new StringToken("e"), p),
-                                                       new Range(new StringToken("m"), min)));
-        assert S.equals(S2);
-
-        S = all.restrictTo(normal);
-        assert S.equals(new HashSet<AbstractBounds>(Arrays.asList(normal)));
-    }
-
-    public void testNoIntersectionWrapped()
-    {
-        IPartitioner p = new OrderPreservingPartitioner();
-        Range node = new Range(new StringToken("z"), new StringToken("a"));
-        Bounds bounds;
-
-        bounds = new Bounds(new StringToken("m"), new StringToken("n"), p);
-        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
-
-        bounds = new Bounds(new StringToken("b"), node.left, p);
-        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
-    }
-
-    public void testSmallBoundsFullRange()
-    {
-        IPartitioner p = new OrderPreservingPartitioner();
-        Range node;
-        Bounds bounds = new Bounds(new StringToken("b"), new StringToken("c"), p);
-
-        node = new Range(new StringToken("d"), new StringToken("d"));
-        assert bounds.restrictTo(node).equals(new HashSet(Arrays.asList(bounds)));
-    }
-
-    public void testNoIntersectionUnwrapped()
-    {
-        IPartitioner p = new OrderPreservingPartitioner();
-        Token min = p.getMinimumToken();
-        Range node = new Range(new StringToken("m"), new StringToken("n"));
-        Bounds bounds;
-
-        bounds = new Bounds(new StringToken("z"), min, p);
-        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
-
-        bounds = new Bounds(new StringToken("a"), node.left, p);
-        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
-
-        bounds = new Bounds(min, new StringToken("b"), p);
-        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
-    }
-}
+package org.apache.cassandra.dht;
+
+import java.util.*;
+
+import junit.framework.TestCase;
+import org.apache.cassandra.utils.FBUtilities;
+
+public class BoundsTest extends TestCase
+{
+    public void testRestrictTo() throws Exception
+    {
+        IPartitioner p = new OrderPreservingPartitioner();
+        Token min = p.getMinimumToken();
+        Range wraps = new Range(new StringToken("m"), new StringToken("e"));
+        Range normal = new Range(wraps.right, wraps.left);
+        Bounds all = new Bounds(min, min, p);
+        Bounds almostAll = new Bounds(new StringToken("a"), min, p);
+
+        Set<AbstractBounds> S;
+        Set<AbstractBounds> S2;
+
+        S = all.restrictTo(wraps);
+        assert S.equals(new HashSet<AbstractBounds>(Arrays.asList(wraps)));
+
+        S = almostAll.restrictTo(wraps);
+        S2 = new HashSet<AbstractBounds>(Arrays.asList(new Bounds(new StringToken("a"), new StringToken("e"), p),
+                                                       new Range(new StringToken("m"), min)));
+        assert S.equals(S2);
+
+        S = all.restrictTo(normal);
+        assert S.equals(new HashSet<AbstractBounds>(Arrays.asList(normal)));
+    }
+
+    public void testNoIntersectionWrapped()
+    {
+        IPartitioner p = new OrderPreservingPartitioner();
+        Range node = new Range(new StringToken("z"), new StringToken("a"));
+        Bounds bounds;
+
+        bounds = new Bounds(new StringToken("m"), new StringToken("n"), p);
+        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
+
+        bounds = new Bounds(new StringToken("b"), node.left, p);
+        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
+    }
+
+    public void testSmallBoundsFullRange()
+    {
+        IPartitioner p = new OrderPreservingPartitioner();
+        Range node;
+        Bounds bounds = new Bounds(new StringToken("b"), new StringToken("c"), p);
+
+        node = new Range(new StringToken("d"), new StringToken("d"));
+        assert bounds.restrictTo(node).equals(new HashSet(Arrays.asList(bounds)));
+    }
+
+    public void testNoIntersectionUnwrapped()
+    {
+        IPartitioner p = new OrderPreservingPartitioner();
+        Token min = p.getMinimumToken();
+        Range node = new Range(new StringToken("m"), new StringToken("n"));
+        Bounds bounds;
+
+        bounds = new Bounds(new StringToken("z"), min, p);
+        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
+
+        bounds = new Bounds(new StringToken("a"), node.left, p);
+        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
+
+        bounds = new Bounds(min, new StringToken("b"), p);
+        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
+    }
+}



Mime
View raw message