Commit 998716b0 authored by chiaming2000's avatar chiaming2000
Browse files

Java API and Simulator:

Added GETVERSION protocol support for Java API and simulator.
parent 4026da95
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -499,6 +499,34 @@ public class DefaultKineticClient implements AdvancedKineticClient {
                endKeyInclusive);
    }

    @Override
    public byte[] getVersion(byte[] key) throws KineticException {

        byte[] version = null;
        KineticMessage request = null;
        KineticMessage response = null;

        try {

            // create get request message
            request = MessageFactory.createGetVersionRequestMessage(key);

            // send request
            response = this.client.request(request);

            version = response.getCommand().getBody().getKeyValue()
                    .getDbVersion().toByteArray();

        } catch (Exception e) {
            KineticException ke = new KineticException(e.getMessage(), e);
            ke.setRequestMessage(request);
            ke.setResponseMessage(response);
            throw ke;
        }

        return version;
    }

    /**
     * {@inheritDoc}
     */
+15 −0
Original line number Diff line number Diff line
@@ -406,6 +406,21 @@ public class MessageFactory {
        return kineticMessage;
    }
    
    public static KineticMessage createGetVersionRequestMessage(byte[] key)
            throws KineticException {

        KineticMessage kineticMessage = createKineticMessageWithBuilder();

        Command.Builder request = (Command.Builder) kineticMessage.getCommand();

        request.getHeaderBuilder().setMessageType(MessageType.GETVERSION);

        request.getBodyBuilder().getKeyValueBuilder()
                .setKey(ByteString.copyFrom(key));

        return kineticMessage;
    }

    public static KineticMessage createFlushDataRequestMessage()
            throws KineticException {

+1 −1
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ public class ClientConfiguration extends Properties {
    /**
     * current supported protocol source commit hash on kinetic-protocol repo.
     */
    public static final String PROTOCOL_SOURCE_HASH = "f74698fba2df685cbfa9b6b9de54f1d2398f8615";
    public static final String PROTOCOL_SOURCE_HASH = "a5e192b2a42e2919ba3bba5916de8a2435f81243";

    // kinetic server host
    private String host = "localhost";
+15 −0
Original line number Diff line number Diff line
@@ -218,6 +218,21 @@ public interface KineticClient extends GenericKineticClient {
     */
    public Entry get(byte[] key) throws KineticException;

    /**
     * Get the version of the entry associated with the specified key.
     * 
     * @param key
     *            the key used to obtain the version of the matched entry.
     * 
     * @return the version of the Entry in the persistent store if there is a
     *         match. Otherwise, returns null.
     * 
     * @throws KineticException
     *             if any internal error occurred.
     * 
     */
    public byte[] getVersion(byte[] key) throws KineticException;

    /**
     * Get the <code>Entry</code> associated with the specified key
     * asynchronously.
+2 −0
Original line number Diff line number Diff line
@@ -75,6 +75,8 @@ public class CommandManager {
        handlerMap.put(MessageType.GETNEXT, kvHandler);
        handlerMap.put(MessageType.GETPREVIOUS, kvHandler);

        handlerMap.put(MessageType.GETVERSION, kvHandler);

        handlerMap.put(MessageType.GETKEYRANGE, new RangeOpHandler());

        this.handlerMap.put(MessageType.SECURITY, new SecurityOpHandler());
Loading