Package org.jscsi.initiator.connection

Examples of org.jscsi.initiator.connection.Connection


    /** {@inheritDoc} */
    @Override
    public final boolean login (final Session session) throws Exception {

        final Connection connection = session.getNextFreeConnection();
        connection.nextState(new GetConnectionsRequestState(connection));
        session.releaseUsedConnection(connection);
        return true;
    }
View Full Code Here


    /** {@inheritDoc} */
    @Override
    public final boolean logoutSession (final ITask task, final Session session) throws Exception {

        final Connection connection = session.getNextFreeConnection();
        connection.getSession().addOutstandingTask(connection, task);
        connection.nextState(new LogoutRequestState(connection, LogoutReasonCode.CLOSE_SESSION));
        return true;
    }
View Full Code Here

        int startAddress = logicalBlockAddress;
        final long blockSize = session.getBlockSize();
        long totalBlocks = (long) Math.ceil(length / (double) blockSize);
        long bytes2Process = length;

        final Connection connection = session.getNextFreeConnection();
        connection.getSession().addOutstandingTask(connection, task);

        // first stage
        short blocks = (short) Math.min(READ_FIRST_STAGE_BLOCKS, totalBlocks);

        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Now reading sequences of length " + blocks + " blocks.");
        }

        connection.nextState(new ReadRequestState(connection, dst, TaskAttributes.SIMPLE, (int) Math.min(bytes2Process, blocks * blockSize), startAddress, blocks));
        startAddress += blocks;
        totalBlocks -= blocks;
        bytes2Process -= blocks * blockSize;

        // second stage
        blocks = (short) Math.min(READ_SECOND_STAGE_BLOCKS, totalBlocks);

        if (blocks > 0) {

            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("Now reading sequences of length " + blocks + " blocks.");
            }
            connection.nextState(new ReadRequestState(connection, dst, TaskAttributes.SIMPLE, (int) Math.min(bytes2Process, blocks * blockSize), startAddress, blocks));
            startAddress += blocks;
            totalBlocks -= blocks;
            bytes2Process -= blocks * blockSize;
        }

        // third stage
        blocks = (short) Math.min(READ_THIRD_STAGE_BLOCKS, totalBlocks);

        while (blocks > 0) {

            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("Now reading sequences of length " + blocks + " blocks.");
            }

            connection.nextState(new ReadRequestState(connection, dst, TaskAttributes.SIMPLE, (int) Math.min(bytes2Process, blocks * blockSize), startAddress, blocks));
            startAddress += blocks;
            totalBlocks -= blocks;
            blocks = (short) Math.min(READ_THIRD_STAGE_BLOCKS, totalBlocks);
        }
        return true;
View Full Code Here

        final long blockSize = session.getBlockSize();
        int totalBlocks = (int) Math.ceil(length / (double) blockSize);
        long bytes2Process = length;
        int bufferPosition = 0;

        final Connection connection = session.getNextFreeConnection();
        connection.getSession().addOutstandingTask(connection, task);

        // first stage
        short blocks = (short) Math.min(WRITE_FIRST_STAGE_BLOCKS, totalBlocks);

        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Now sending sequences of length " + blocks + " blocks.");
        }

        int expectedDataTransferLength = (int) Math.min(bytes2Process, blocks * blockSize);
        connection.nextState(new WriteRequestState(connection, src, bufferPosition, TaskAttributes.SIMPLE, expectedDataTransferLength, startAddress, blocks));
        startAddress += blocks;
        totalBlocks -= blocks;
        bytes2Process -= blocks * blockSize;
        bufferPosition += expectedDataTransferLength;

        // second stage
        blocks = (short) Math.min(WRITE_SECOND_STAGE_BLOCKS, totalBlocks);

        if (blocks > 0) {

            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("Now sending sequences of length " + blocks + " blocks.");
                LOGGER.info("Remaining, DataSegmentLength: " + bytes2Process + ", " + expectedDataTransferLength);
            }

            expectedDataTransferLength = (int) Math.min(bytes2Process, blocks * blockSize);
            connection.nextState(new WriteRequestState(connection, src, bufferPosition, TaskAttributes.SIMPLE, expectedDataTransferLength, startAddress, blocks));
            startAddress += blocks;
            totalBlocks -= blocks;
            bytes2Process -= blocks * blockSize;
            bufferPosition += expectedDataTransferLength;
        }

        // third stage
        blocks = (short) Math.min(WRITE_THIRD_STAGE_BLOCKS, totalBlocks);

        while (blocks > 0) {

            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("Now sending sequences of length " + blocks + " blocks.");
            }

            expectedDataTransferLength = (int) Math.min(bytes2Process, blocks * blockSize);
            connection.nextState(new WriteRequestState(connection, src, bufferPosition, TaskAttributes.SIMPLE, expectedDataTransferLength, startAddress, blocks));
            startAddress += blocks;
            totalBlocks -= blocks;
            blocks = (short) Math.min(READ_THIRD_STAGE_BLOCKS, totalBlocks);
            bufferPosition += expectedDataTransferLength;
        }
View Full Code Here

    @Override
    public final boolean getCapacity (final Session session, final TargetCapacityInformations capacityInformation) throws Exception {

        if (capacityInformation == null) { throw new NullPointerException(); }

        final Connection connection = session.getNextFreeConnection();
        if (connection == null) { throw new NullPointerException(); }

        connection.nextState(new CapacityRequestState(connection, capacityInformation, TaskAttributes.SIMPLE));
        session.releaseUsedConnection(connection);
        return true;
    }
View Full Code Here

     * @return AbsConnection The Connection Object.
     */
    public final Connection getConnection (final Session session, final Configuration initConfiguration, final InetSocketAddress inetAddress, final short initConnectionID) {

        try {
            final Connection newConnection = new Connection(session, initConfiguration, inetAddress, initConnectionID);
            return newConnection;
        } catch (Exception e) {
            LOGGER.error("This exception is thrown: " + e);
            e.printStackTrace();
            return null;
View Full Code Here

    /** {@inheritDoc} */
    @Override
    public Connection getConnection () throws NoSuchConnectionException {

        Connection retConnection;
        try {
            retConnection = freeConnections.take();
            return retConnection;

        } catch (InterruptedException e) {
View Full Code Here

TOP

Related Classes of org.jscsi.initiator.connection.Connection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.