com.scudata.dm.Machines Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of esproc Show documentation
Show all versions of esproc Show documentation
SPL(Structured Process Language) A programming language specially for structured data computing.
package com.scudata.dm;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.ArrayList;
import com.scudata.common.MessageManager;
import com.scudata.common.RQException;
import com.scudata.common.StringUtils;
import com.scudata.parallel.UnitClient;
import com.scudata.resources.EngineMessage;
/**
* "ip:port"
* ":port"??????127.0.0.1
* ":"???????Լ?????
* ""??????
*
*/
public class Machines implements Externalizable{
private String []hosts;
private int []ports;
public Machines() {
}
private String parseHost(String str) {
String host=null,defaultHost="127.0.0.1";
int index = str.lastIndexOf(':');
if (index == -1) {//û??ð??
MessageManager mm = EngineMessage.get();
throw new RQException("HS" + mm.getMessage("function.invalidParam")+": "+str);
}else if( index==0 ) {//ð?ſ?ͷΪ???طֻ?
if(str.length()>1) {
host = defaultHost;
}//????Ϊ??ð?ű?ʾ?????̣???null??host
}else {
host = str.substring(0, index);
}
return host;
}
private int parsePort(String str) {
int index = str.lastIndexOf(':');
if(str.length()==1) {//??ð??ʱ??????0?˿?
return 0;
}
int port = Integer.parseInt(str.substring(index + 1));
return port;
}
public boolean set(Object o) {
if (o == null) {
//MessageManager mm = EngineMessage.get();
//throw new RQException(errorMsg + mm.getMessage("function.invalidParam"));
} else if (o instanceof String) {
String str = (String)o; // ip:port
if(!StringUtils.isValidString(str)) {
MessageManager mm = EngineMessage.get();
throw new RQException("HS" + mm.getMessage("function.invalidParam"));
}
hosts = new String[]{ parseHost(str) };
ports = new int[]{ parsePort(str) };
} else if (o instanceof Sequence) {
Sequence seq = (Sequence)o;
int count = seq.length();
if (count == 0) {
return false;
}
ArrayList listH = new ArrayList();
ArrayListlistP = new ArrayList();
for (int i = 0; i < count; ++i) {
Object obj = seq.get(i + 1);
if (obj==null) {
continue;
}else if(obj instanceof String) {
String str = (String)obj; // ip:port
if(!StringUtils.isValidString(str)) {
continue;
}
listH.add( parseHost(str) );
listP.add( parsePort(str) );
}else if(obj instanceof UnitClient){
UnitClient uc = (UnitClient)obj;
listH.add( uc.getHost() );
listP.add( uc.getPort() );
}else{
//????ʶ?Ķ???
return false;
}
}
hosts = new String[listH.size()];
ports = new int[listH.size()];
for(int i=0;i
© 2015 - 2024 Weber Informatics LLC | Privacy Policy