io.firebus.tools.Executor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of firebus-core Show documentation
Show all versions of firebus-core Show documentation
Firebus core functionality
package io.firebus.tools;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Properties;
import java.util.logging.Logger;
import io.firebus.FirebusAdmin;
import io.firebus.Payload;
import io.firebus.exceptions.FunctionErrorException;
import io.firebus.exceptions.FunctionTimeoutException;
import io.firebus.information.FunctionInformation;
import io.firebus.information.NodeInformation;
public class Executor {
private Logger logger = Logger.getLogger("io.firebus");
protected FirebusAdmin firebus;
public Executor(String[] args) {
for(int i = 0; i < args.length; i++) {
String swt = args[i];
if(swt.equals("-fb") && args.length > i + 1) {
String param = args[++i];
String[] parts = param.split("/");
firebus = new FirebusAdmin(parts[0], parts[1]);
} else if(swt.equals("-ka") && args.length > i + 1) {
String param = args[++i];
String[] parts = param.split(":");
firebus.addKnownNodeAddress(parts[0], Integer.parseInt(parts[1]));
}
}
if(firebus == null)
{
firebus = new FirebusAdmin();
}
}
public String execute(String line, Properties headers) throws IOException
{
String ret = "";
String[] parts = line.split(" ");
String command = parts[0];
if(command.equals("req") || command.equals("pub") || command.equals("si"))
{
String functionName = "";
Payload payload = null;
String inputFileName = null;
if(parts.length > 1)
{
functionName = parts[1];
if(parts.length > 2)
{
inputFileName = getSwitchValue(parts, "if");
int dataStart = command.length() + functionName.length() + 2;
for(int i = 2; i < parts.length; i+=2)
{
if(parts[i].startsWith("-"))
dataStart += parts[i].length() + parts[i + 1].length() + 2;
else
break;
}
if(dataStart < line.length())
{
payload = new Payload(line.substring(dataStart).getBytes());
}
if(payload == null && inputFileName != null)
{
try
{
FileInputStream fis = new FileInputStream(inputFileName);
byte[] data = new byte[fis.available()];
fis.read(data);
fis.close();
payload = new Payload(data);
payload.metadata.put("filename", inputFileName);
}
catch(IOException e)
{
logger.severe(e.getMessage());
}
}
}
}
if(payload == null)
{
payload = new Payload();
}
Iterator
© 2015 - 2024 Weber Informatics LLC | Privacy Policy