Commit 2d1e4ce1 authored by chiaming2000's avatar chiaming2000
Browse files

Added Java API to set/get expected WWN. If set, the expected WWN will be

used to compare with the connected Drive's WWN. A KineticException is
raised if WWN does not match.
parent 1e1295c7
Loading
Loading
Loading
Loading
+23 −7
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ public class ClientProxy {
        }
        
        if (this.isConnectionIdSetByServer == false) {
            throw new KineticException ("Did not receive a Status message from service.");
            throw new KineticException("Hand shake failed with the service.");
        }
    }
    
@@ -166,13 +166,29 @@ public class ClientProxy {
            this.connectionID = kresponse.getCommand().getHeader()
                    .getConnectionID();

            if (this.config.getExpectedWwn() != null) {

                String recvd = kresponse.getCommand().getBody().getGetLog()
                        .getConfiguration().getWorldWideName().toStringUtf8();

                if (config.getExpectedWwn().equals(recvd) == false) {

                    this.close();

                    logger.log(Level.SEVERE, "wwn does not match., expected="
                            + config.getExpectedWwn() + ", but received: "
                            + recvd);
                } else {
                    // set flag to true
                    this.isConnectionIdSetByServer = true;
                }
            } else {
                // set flag to true
                this.isConnectionIdSetByServer = true;
            }

            // count down
            this.cidLatch.countDown();

            logger.fine("set connection Id: " + this.connectionID);
        }

    }
+19 −11
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@ public class IoHandler {
	 */
    private void init() throws KineticException {

        try {
            // get the transport provider for this kinetic instance.
            getTransport();

@@ -115,6 +116,13 @@ public class IoHandler {

            // init transport
            this.transport.init(messageHandler);
        } catch (KineticException ke) {
            close();
            throw ke;
        } catch (Exception e) {
            close();
            throw new KineticException(e);
        }
    }

	public ClientProxy getClient() {
+29 −0
Original line number Diff line number Diff line
@@ -120,6 +120,9 @@ public class ClientConfiguration extends Properties {
     */
    private int asyncQueueSize = 10;

    // expected wwn to connect to.
    private String expectedWwn = null;

    /**
     * Client configuration constructor.
     * 
@@ -514,4 +517,30 @@ public class ClientConfiguration extends Properties {
        return PROTOCOL_SOURCE_HASH;
    }

    /**
     * Set expected WWN for the connected drive.
     * <p>
     * If set, the drive's WWN will be validated by the Java Client Runtime
     * library with the expected WWN when a connection is created to the drive.
     * <p>
     * A connection creation will fail if the expected WWN is set to a non-empty
     * value and it does not match the drive's WWN. In this case, the connection
     * is closed and KineticException is raised.
     * 
     * @param wwn
     *            the expected drive's WWN to be validated.
     */
    public void setExpectedWwn(String wwn) {
        this.expectedWwn = wwn;
    }

    /**
     * Get expected WWN set by the application.
     * 
     * @return expected WWN set by the application.
     */
    public String getExpectedWwn() {
        return this.expectedWwn;
    }

}