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;
}
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;
}
}
}
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);
}
}
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);
}
}
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;
}
Aggregations