@Override public byte[] serializeObject(Object object) throws Exception { if (object instanceof Function) { Function fn = (Function) object; return serialize(object, (byte) fn.getFunctionId().ordinal()); } else { return serialize(object, (byte) FunctionId.OTHER.ordinal()); } }
private Object deserialize(byte fid, ByteBuffer buffer, int length) throws Exception { switch (FunctionId.values()[fid]) { case REGISTER_PARTITION_PROVIDER: return RegisterPartitionProviderFunction.deserialize(buffer, length); case REGISTER_PARTITION_REQUEST: return RegisterPartitionRequestFunction.deserialize(buffer, length); case REPORT_PARTITION_AVAILABILITY: return ReportPartitionAvailabilityFunction.deserialize(buffer, length); case NODE_HEARTBEAT: return NodeHeartbeatFunction.deserialize(buffer, length); case START_TASKS: return StartTasksFunction.deserialize(buffer, length); case NOTIFY_TASK_COMPLETE: return NotifyTaskCompleteFunction.deserialize(buffer, length); case NOTIFY_JOBLET_CLEANUP: return NotifyJobletCleanupFunction.deserialize(buffer, length); case CLEANUP_JOBLET: return CleanupJobletFunction.deserialize(buffer, length); } return javaSerde.deserializeObject(buffer, length); } }
public static void serialize(OutputStream out, Object object) throws Exception { ReportPartitionAvailabilityFunction fn = (ReportPartitionAvailabilityFunction) object; DataOutputStream dos = new DataOutputStream(out); // Write PartitionId writePartitionId(dos, fn.getPartitionId()); // Write NetworkAddress writeNetworkAddress(dos, fn.getNetworkAddress()); } }
@Override public Exception deserializeException(ByteBuffer buffer, int length) throws Exception { if (length < FID_CODE_SIZE) { throw new IllegalStateException("Message size too small: " + length); } byte fid = buffer.get(); if (fid != FunctionId.OTHER.ordinal()) { throw new IllegalStateException("Expected FID for OTHER, found: " + fid); } return (Exception) deserialize(fid, buffer, length - FID_CODE_SIZE); }
@Override public void sendApplicationMessageToNC(byte[] data, DeploymentId deploymentId, String nodeId) throws Exception { SendApplicationMessageFunction fn = new SendApplicationMessageFunction(data, deploymentId, nodeId); ipcHandle.send(-1, fn, null); }
@Override public void startTasks(DeploymentId deploymentId, JobId jobId, byte[] planBytes, List<TaskAttemptDescriptor> taskDescriptors, Map<ConnectorDescriptorId, IConnectorPolicy> connectorPolicies, Set<JobFlag> flags, Map<byte[], byte[]> jobParameters, DeployedJobSpecId deployedJobSpecId, long jobStartTime) throws Exception { StartTasksFunction stf = new StartTasksFunction(deploymentId, jobId, planBytes, taskDescriptors, connectorPolicies, flags, jobParameters, deployedJobSpecId, jobStartTime); ipcHandle.send(-1, stf, null); }
@Override public void dumpState(String stateDumpId) throws Exception { StateDumpRequestFunction dsf = new StateDumpRequestFunction(stateDumpId, ccId); ipcHandle.send(-1, dsf, null); }
@Override public void notifyShutdown(String nodeId) throws Exception { ShutdownResponseFunction sdrf = new ShutdownResponseFunction(nodeId); ipcHandle.send(-1, sdrf, null); }
@Override public void registerNode(NodeRegistration reg, int registrationId) throws Exception { RegisterNodeFunction fn = new RegisterNodeFunction(reg, registrationId); ipcHandle.send(-1, fn, null); }
@Override public void registerPartitionRequest(PartitionRequest partitionRequest) throws Exception { RegisterPartitionRequestFunction fn = new RegisterPartitionRequestFunction(partitionRequest); ipcHandle.send(-1, fn, null); }
@Override public void notifyDeployedJobSpecFailure(DeployedJobSpecId deployedJobSpecId, String nodeId) throws Exception { ReportDeployedJobSpecFailureFunction fn = new ReportDeployedJobSpecFailureFunction(deployedJobSpecId, nodeId); ipcHandle.send(-1, fn, null); }
@Override public void shutdown(boolean terminateNCService) throws Exception { ShutdownRequestFunction sdrf = new ShutdownRequestFunction(terminateNCService, ccId); ipcHandle.send(-1, sdrf, null); }
@Override public void unregisterNode(String nodeId) throws Exception { UnregisterNodeFunction fn = new UnregisterNodeFunction(nodeId); ipcHandle.send(-1, fn, null); }
@Override public void registerPartitionProvider(PartitionDescriptor partitionDescriptor) throws Exception { RegisterPartitionProviderFunction fn = new RegisterPartitionProviderFunction(partitionDescriptor); ipcHandle.send(-1, fn, null); }
@Override public void registerResultPartitionLocation(JobId jobId, ResultSetId rsId, boolean orderedResult, boolean emptyResult, int partition, int nPartitions, NetworkAddress networkAddress) throws Exception { RegisterResultPartitionLocationFunction fn = new RegisterResultPartitionLocationFunction(jobId, rsId, orderedResult, emptyResult, partition, nPartitions, networkAddress); ipcHandle.send(-1, fn, null); }
@Override public void notifyTaskFailure(JobId jobId, TaskAttemptId taskId, String nodeId, List<Exception> exceptions) throws Exception { NotifyTaskFailureFunction fn = new NotifyTaskFailureFunction(jobId, taskId, nodeId, exceptions); ipcHandle.send(-1, fn, null); }
@Override public void reportProfile(String id, List<JobProfile> profiles) throws Exception { ReportProfileFunction fn = new ReportProfileFunction(id, profiles); ipcHandle.send(-1, fn, null); }
@Override public void setValue(Map<String, NodeControllerInfo> result) { new IPCResponder<CCNCFunctions.GetNodeControllersInfoResponseFunction>(handle, -1) .setValue(new CCNCFunctions.GetNodeControllersInfoResponseFunction(result)); }
@Override public void sendApplicationMessageToCC(byte[] data, DeploymentId deploymentId, String nodeId) throws Exception { SendApplicationMessageFunction fn = new SendApplicationMessageFunction(data, deploymentId, nodeId); ipcHandle.send(-1, fn, null); }