Search in sources :

Example 16 with ServiceRequestBuffer

use of org.firebirdsql.gds.ServiceRequestBuffer in project jaybird by FirebirdSQL.

the class FBServiceManager method createRequestBuffer.

protected ServiceRequestBuffer createRequestBuffer(FbService service, int operation, int options) {
    ServiceRequestBuffer srb = service.createServiceRequestBuffer();
    srb.addArgument(operation);
    if (getDatabase() != null) {
        srb.addArgument(isc_spb_dbname, getDatabase());
    }
    srb.addArgument(isc_spb_options, options);
    return srb;
}
Also used : ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer)

Example 17 with ServiceRequestBuffer

use of org.firebirdsql.gds.ServiceRequestBuffer in project jaybird by FirebirdSQL.

the class FBServiceManager method queueService.

public void queueService(FbService service) throws SQLException, IOException {
    OutputStream currentLogger = getLogger();
    ServiceRequestBuffer infoSRB = service.createServiceRequestBuffer();
    infoSRB.addArgument(isc_info_svc_to_eof);
    int bufferSize = BUFFER_SIZE;
    boolean processing = true;
    while (processing) {
        byte[] buffer = service.getServiceInfo(null, infoSRB, bufferSize);
        switch(buffer[0]) {
            case isc_info_svc_to_eof:
                int dataLength = iscVaxInteger2(buffer, 1);
                if (dataLength == 0) {
                    if (buffer[3] != isc_info_end)
                        throw new SQLException("Unexpected end of stream reached.");
                    else {
                        processing = false;
                        break;
                    }
                }
                if (currentLogger != null) {
                    currentLogger.write(buffer, 3, dataLength);
                }
                break;
            case isc_info_truncated:
                bufferSize = bufferSize * 2;
                break;
            case isc_info_end:
                processing = false;
                break;
        }
    }
}
Also used : ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer) SQLException(java.sql.SQLException) OutputStream(java.io.OutputStream)

Example 18 with ServiceRequestBuffer

use of org.firebirdsql.gds.ServiceRequestBuffer in project jaybird by FirebirdSQL.

the class FBStreamingBackupManager method executeServiceRestoreOperation.

private void executeServiceRestoreOperation(FbService service, ServiceRequestBuffer srb) throws SQLException {
    try {
        service.startServiceAction(srb);
        OutputStream currentLogger = getLogger();
        ServiceRequestBuffer infoSRB = service.createServiceRequestBuffer();
        ServiceParameterBuffer infoSPB = null;
        infoSRB.addArgument(isc_info_svc_stdin);
        infoSRB.addArgument(isc_info_svc_line);
        if (this.verbose && currentLogger == null)
            throw new SQLException("Verbose mode was requested but there is no logger provided.");
        int bufferSize = BUFFER_SIZE;
        byte[] stdinBuffer = new byte[MAX_RESTORE_CHUNK];
        byte[] newLine = System.lineSeparator().getBytes();
        boolean processing = true;
        boolean sending = true;
        byte[] buffer;
        while (processing || infoSPB != null) {
            buffer = service.getServiceInfo(infoSPB, infoSRB, bufferSize);
            if (infoSPB != null && !sending) {
                infoSRB = service.createServiceRequestBuffer();
                infoSRB.addArgument(isc_info_svc_line);
            }
            infoSPB = null;
            for (int codePos = 0; codePos < buffer.length && buffer[codePos] != isc_info_end; ) {
                switch(buffer[codePos]) {
                    case isc_info_svc_stdin:
                        int requestedBytes = Math.min(iscVaxInteger(buffer, ++codePos, 4), stdinBuffer.length);
                        codePos += 4;
                        if (requestedBytes > 0) {
                            int actuallyReadBytes = restoreInputStream.read(stdinBuffer, 0, requestedBytes);
                            if (actuallyReadBytes > 0) {
                                infoSPB = service.createServiceParameterBuffer();
                                if (stdinBuffer.length == actuallyReadBytes)
                                    infoSPB.addArgument(isc_info_svc_line, stdinBuffer);
                                else
                                    infoSPB.addArgument(isc_info_svc_line, Arrays.copyOfRange(stdinBuffer, 0, actuallyReadBytes));
                            }
                            restoreInputStream.mark(2);
                            if (restoreInputStream.read() < 0)
                                sending = false;
                            else
                                restoreInputStream.reset();
                        }
                        break;
                    case isc_info_truncated:
                        bufferSize *= 2;
                        ++codePos;
                        break;
                    case isc_info_svc_line:
                        int bytesToLog = readOutput(buffer, codePos, currentLogger);
                        codePos += 3;
                        switch(bytesToLog) {
                            case DATA_NOT_READY:
                                ++codePos;
                                break;
                            case END_OF_STREAM:
                                processing = false;
                                break;
                            default:
                                codePos += bytesToLog;
                                if (currentLogger != null)
                                    currentLogger.write(newLine);
                        }
                        break;
                    case isc_info_end:
                        break;
                    default:
                        throw new SQLException("Unexpected response from service.");
                }
            }
        }
    } catch (IOException ioe) {
        throw new SQLException(ioe);
    }
}
Also used : ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer) SQLException(java.sql.SQLException) OutputStream(java.io.OutputStream) ServiceParameterBuffer(org.firebirdsql.gds.ServiceParameterBuffer) IOException(java.io.IOException)

Example 19 with ServiceRequestBuffer

use of org.firebirdsql.gds.ServiceRequestBuffer in project jaybird by FirebirdSQL.

the class FBStreamingBackupManager method executeServiceBackupOperation.

private void executeServiceBackupOperation(FbService service, ServiceRequestBuffer srb) throws SQLException {
    try {
        service.startServiceAction(srb);
        ServiceRequestBuffer infoSRB = service.createServiceRequestBuffer();
        infoSRB.addArgument(isc_info_svc_to_eof);
        int bufferSize = backupBufferSize;
        boolean processing = true;
        while (processing) {
            byte[] buffer = service.getServiceInfo(null, infoSRB, bufferSize);
            switch(buffer[0]) {
                case isc_info_svc_to_eof:
                    if (readOutput(buffer, 0, backupOutputStream) == END_OF_STREAM) {
                        processing = false;
                    }
                    break;
                case isc_info_truncated:
                    bufferSize = bufferSize * 2;
                    break;
                case isc_info_end:
                    processing = false;
                    break;
                default:
                    throw new SQLException("Unexpected response from service.");
            }
        }
    } catch (IOException ioe) {
        throw new SQLException(ioe);
    }
}
Also used : ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 20 with ServiceRequestBuffer

use of org.firebirdsql.gds.ServiceRequestBuffer in project jaybird by FirebirdSQL.

the class AbstractFbService method getDescribeServiceRequestBuffer.

protected ServiceRequestBuffer getDescribeServiceRequestBuffer() {
    ServiceRequestBuffer srb = createServiceRequestBuffer();
    srb.addArgument(isc_info_svc_server_version);
    return srb;
}
Also used : ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer)

Aggregations

ServiceRequestBuffer (org.firebirdsql.gds.ServiceRequestBuffer)40 FbService (org.firebirdsql.gds.ng.FbService)20 SQLException (java.sql.SQLException)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 FBManager (org.firebirdsql.management.FBManager)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 ServiceParameterBuffer (org.firebirdsql.gds.ServiceParameterBuffer)1 AbstractFbWireService (org.firebirdsql.gds.ng.wire.AbstractFbWireService)1 FbWireService (org.firebirdsql.gds.ng.wire.FbWireService)1 WireServiceConnection (org.firebirdsql.gds.ng.wire.WireServiceConnection)1