use of org.netxms.base.NXCPMessage in project netxms by netxms.
the class NXCSession method sendFileStream.
/**
* Send binary message, data loaded from provided input stream and splitted
* into chunks of {@value FILE_BUFFER_SIZE} bytes
*
* @param requestId request ID
* @param inputStream data input stream
* @param listener progress listener
* @param allowStreamCompression true if data stream compression is allowed
* @throws IOException if socket I/O error occurs
* @throws NXCException if NetXMS server returns an error or operation was timed out
*/
private void sendFileStream(final long requestId, final InputStream inputStream, ProgressListener listener, boolean allowStreamCompression) throws IOException, NXCException {
NXCPMessage msg = new NXCPMessage(NXCPCodes.CMD_FILE_DATA, requestId);
msg.setBinaryMessage(true);
Deflater compressor = allowStreamCompression ? new Deflater(9) : null;
msg.setStream(true, allowStreamCompression);
boolean success = false;
final byte[] buffer = new byte[FILE_BUFFER_SIZE];
long bytesSent = 0;
while (true) {
final int bytesRead = inputStream.read(buffer);
if (bytesRead < FILE_BUFFER_SIZE) {
msg.setEndOfFile(true);
}
if ((compressor != null) && (bytesRead > 0)) {
byte[] compressedData = new byte[compressor.deflateBound(bytesRead) + 4];
compressor.setInput(buffer, 0, bytesRead, false);
compressor.setOutput(compressedData, 4, compressedData.length - 4);
if (compressor.deflate(JZlib.Z_SYNC_FLUSH) != JZlib.Z_OK)
throw new NXCException(RCC.IO_ERROR);
int length = compressedData.length - compressor.getAvailOut();
byte[] payload = Arrays.copyOf(compressedData, length);
// DEFLATE method
payload[0] = 2;
// reserved
payload[1] = 0;
// uncompressed length, high bits
payload[2] = (byte) ((bytesRead >> 8) & 0xFF);
// uncompressed length, low bits
payload[3] = (byte) (bytesRead & 0xFF);
msg.setBinaryData(payload);
} else {
msg.setBinaryData((bytesRead == -1) ? new byte[0] : Arrays.copyOf(buffer, bytesRead));
}
sendMessage(msg);
bytesSent += (bytesRead == -1) ? 0 : bytesRead;
if (listener != null)
listener.markProgress(bytesSent);
if (bytesRead < FILE_BUFFER_SIZE) {
success = true;
break;
}
}
if (compressor != null)
compressor.deflateEnd();
if (!success) {
NXCPMessage abortMessage = new NXCPMessage(NXCPCodes.CMD_ABORT_FILE_TRANSFER, requestId);
abortMessage.setBinaryMessage(true);
sendMessage(abortMessage);
waitForRCC(abortMessage.getMessageId());
}
}
use of org.netxms.base.NXCPMessage in project netxms by netxms.
the class NXCSession method getNodeSoftwarePackages.
/**
* Get list of software packages installed on node.
*
* @param nodeId node object identifier
* @return root component
* @throws IOException if socket I/O error occurs
* @throws NXCException if NetXMS server returns an error or operation was timed out
*/
public List<SoftwarePackage> getNodeSoftwarePackages(long nodeId) throws IOException, NXCException {
final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_NODE_SOFTWARE);
msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
sendMessage(msg);
final NXCPMessage response = waitForRCC(msg.getMessageId());
int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_ELEMENTS);
List<SoftwarePackage> packages = new ArrayList<SoftwarePackage>(count);
long varId = NXCPCodes.VID_ELEMENT_LIST_BASE;
for (int i = 0; i < count; i++) {
packages.add(new SoftwarePackage(response, varId));
varId += 10;
}
return packages;
}
use of org.netxms.base.NXCPMessage in project netxms by netxms.
the class NXCSession method deleteDciSummaryTable.
/**
* Delete DCI summary table.
*
* @param id The ID of the summary table
* @throws IOException if socket I/O error occurs
* @throws NXCException if NetXMS server returns an error or operation was timed out
*/
public void deleteDciSummaryTable(int id) throws IOException, NXCException {
final NXCPMessage msg = newMessage(NXCPCodes.CMD_DELETE_SUMMARY_TABLE);
msg.setFieldInt32(NXCPCodes.VID_SUMMARY_TABLE_ID, id);
sendMessage(msg);
waitForRCC(msg.getMessageId());
}
use of org.netxms.base.NXCPMessage in project netxms by netxms.
the class NXCSession method deleteMappingTable.
/**
* Delete mapping table
*
* @param id mapping table ID
* @throws IOException if socket I/O error occurs
* @throws NXCException if NetXMS server returns an error or operation was timed out
*/
public void deleteMappingTable(int id) throws IOException, NXCException {
final NXCPMessage msg = newMessage(NXCPCodes.CMD_DELETE_MAPPING_TABLE);
msg.setFieldInt32(NXCPCodes.VID_MAPPING_TABLE_ID, id);
sendMessage(msg);
waitForRCC(msg.getMessageId());
}
use of org.netxms.base.NXCPMessage in project netxms by netxms.
the class NXCSession method compileScript.
/**
* Compile NXSL script on server. Field *success* in compilation result object will indicate compilation status.
* If compilation fails, field *errorMessage* will contain compilation error message.
*
* @param source script source
* @param serialize flag to indicate if compiled script should be serialized and sent back to client
* @return script compilation result object
* @throws IOException if socket I/O error occurs
* @throws NXCException if NetXMS server returns an error or operation was timed out
*/
public ScriptCompilationResult compileScript(String source, boolean serialize) throws IOException, NXCException {
NXCPMessage msg = newMessage(NXCPCodes.CMD_COMPILE_SCRIPT);
msg.setField(NXCPCodes.VID_SCRIPT, source);
msg.setField(NXCPCodes.VID_SERIALIZE, serialize);
sendMessage(msg);
return new ScriptCompilationResult(waitForRCC(msg.getMessageId()));
}
Aggregations