Commit de94d4e8 authored by Andrew Mitchell's avatar Andrew Mitchell
Browse files

Updated connection factory to return nonblocking connection instead of...

Updated connection factory to return nonblocking connection instead of ConnectionHandle with both connections inside. Since the threadsafe connections are not strictly threadsafe if used simultaneously, it is better not to pair them together
parent cbd0bacd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ add_library(kinetic_client
    src/main/socket_wrapper.cc
    src/main/blocking_kinetic_connection.cc
    src/main/threadsafe_blocking_kinetic_connection.cc
    src/main/connection_handle.cc

    src/main/key_range_iterator.cc
)
add_dependencies(kinetic_client
+7 −2
Original line number Diff line number Diff line
@@ -47,8 +47,13 @@ class BlockingKineticConnection {
    /// @param[in] network_timeout_seconds  If an operation goes more than network_timeout_seconds
    ///                                     seconds without receiving data the operation will fail
    explicit BlockingKineticConnection(
        NonblockingKineticConnection* nonblocking_connection,
            shared_ptr<NonblockingKineticConnection> nonblocking_connection,
        unsigned int network_timeout_seconds);

    explicit BlockingKineticConnection(
            unique_ptr<NonblockingKineticConnection> nonblocking_connection,
            unsigned int network_timeout_seconds);

    virtual ~BlockingKineticConnection();

    /// If the drive has a non-zero cluster version, requests will fail unless the developer
@@ -157,7 +162,7 @@ class BlockingKineticConnection {
    /// Helper method for translating a StatusCode from the drive into an API client KineticStatus
    /// object
    KineticStatus GetKineticStatus(StatusCode code);
    NonblockingKineticConnection* nonblocking_connection_;
    shared_ptr<NonblockingKineticConnection> nonblocking_connection_;
    const unsigned int network_timeout_seconds_;
    DISALLOW_COPY_AND_ASSIGN(BlockingKineticConnection);
    };
+0 −60
Original line number Diff line number Diff line
/*
 * kinetic-cpp-client
 * Copyright (C) 2014 Seagate Technology.
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */

#ifndef KINETIC_CPP_CLIENT_CONNECTION_HANDLE_H_
#define KINETIC_CPP_CLIENT_CONNECTION_HANDLE_H_

#include "kinetic/blocking_kinetic_connection.h"
#include "kinetic/nonblocking_kinetic_connection.h"
#include "protobufutil/common.h"

namespace kinetic {

/// Represents a single connection to a single Kinetic drive and allows interacting with
/// it in a blocking or non-blocking manner. Blocking and non-blocking operations can be
/// interleaved freely.
class ConnectionHandle {
    public:
    /// Creates a new ConnectionHandle and takes ownership of the given BlockingKineticConnection
    /// and the given nonblocking_connection. Instead of creating instances of ConnectionHandle
    /// directly use the KineticConnectionFactory
    ConnectionHandle(
            BlockingKineticConnection* blocking_connection,
            NonblockingKineticConnection* nonblocking_connection);

    ~ConnectionHandle();

    /// Returns a BlockingKineticConnection reference for using the underlying connection with a
    /// blocking interface
    BlockingKineticConnection& blocking();

    /// Returns a NonblockingKineticConnection reference for using the underlying connection with a
    /// blocking interface
    NonblockingKineticConnection& nonblocking();

    private:
    BlockingKineticConnection* blocking_connection_;
    NonblockingKineticConnection* nonblocking_connection_;
    DISALLOW_COPY_AND_ASSIGN(ConnectionHandle);
};

} // namespace kinetic

#endif  // KINETIC_CPP_CLIENT_CONNECTION_HANDLE_H_
+13 −15
Original line number Diff line number Diff line
@@ -24,10 +24,9 @@
#include "protobufutil/message_stream.h"

#include "kinetic/connection_options.h"
#include "kinetic/connection_handle.h"
#include "kinetic/hmac_provider.h"
#include "kinetic/nonblocking_kinetic_connection.h"
#include "kinetic/blocking_kinetic_connection.h"
#include "kinetic/threadsafe_nonblocking_connection.h"
#include "kinetic/status.h"

namespace kinetic {
@@ -50,24 +49,23 @@ class KineticConnectionFactory {
    /// @param[in] options                  Specifies host, port, user id, etc
    /// @param[in] network_timeout_seconds  If an operation goes more than this many seconds without
    ///                                     data the operation fails
    /// @param[out] connection              Populated with a ConnectionHandle if the request
    /// @param[out] connection              Populated with a NonblockingKineticConnection if the request
    ///                                     succeeds
    virtual Status NewConnection(
    virtual Status NewNonblockingConnection(
            const ConnectionOptions& options,
        unsigned int network_timeout_seconds,
        unique_ptr<ConnectionHandle>& connection);
            unique_ptr <NonblockingKineticConnection>& connection);

    /// Like NewConnection, except the connections available via the ConnectionHandle are safe for
    /// use by multiple threads.
    virtual Status NewThreadsafeConnection(const ConnectionOptions &options,
            unsigned int network_timeout_seconds,
            unique_ptr<ConnectionHandle>& connection);
    /// Like NewConnection, except the connection is safe for use by multiple threads.
    virtual Status NewThreadsafeNonblockingConnection(
            const ConnectionOptions& options,
            unique_ptr <NonblockingKineticConnection>& connection);

    private:
    HmacProvider hmac_provider_;
    Status doNewConnection(ConnectionOptions const &options,
            unsigned int network_timeout_seconds,
            unique_ptr<ConnectionHandle>& connection, bool threadsafe);
    Status doNewConnection(
            ConnectionOptions const& options,
            unique_ptr <NonblockingKineticConnection>& connection,
            bool threadsafe);
};

/// Helper method that creates a new KineticConnectionFactory with
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ class ThreadsafeBlockingKineticConnection : public BlockingKineticConnection {
    /// @param[in] network_timeout_seconds  If an operation goes more than network_timeout_seconds
    ///                                     seconds without receiving data the operation will fail
    explicit ThreadsafeBlockingKineticConnection(
        NonblockingKineticConnection* nonblocking_connection,
        shared_ptr<ThreadsafeNonblockingKineticConnection> nonblocking_connection,
        unsigned int network_timeout_seconds);
    ~ThreadsafeBlockingKineticConnection();

Loading