List of usage examples for java.rmi MarshalledObject MarshalledObject
public MarshalledObject(T obj) throws IOException
MarshalledObject
that contains the serialized representation of the current state of the supplied object. From source file:de.laures.cewolf.taglib.util.KeyGenerator.java
public static int generateKey(Serializable obj) { if (obj == null) { NoKeyException ex = new NoKeyException("assertion failed: can not generate key for null,"); throw ex; }/*w w w. j av a2 s. c o m*/ try { MarshalledObject mo = new MarshalledObject(obj); return mo.hashCode(); } catch (IOException ioex) { log.error("IOException during key generation KeyGenerator.generateKey()", ioex); throw new NoKeyException(obj + " is not serializable."); } }
From source file:edu.cmu.tetrad.data.DataUtils.java
/** * Adds missing data values to cases in accordance with probabilities * specified in a double array which has as many elements as there are * columns in the input dataset. Hence if the first element of the array of * probabilities is alpha, then the first column will contain a -99 (or * other missing value code) in a given case with probability alpha. </p> * This method will be useful in generating datasets which can be used to * test algorithms that handle missing data and/or latent variables. </p> * Author: Frank Wimberly//from w w w .java 2 s. c om * * @param inData The data to which random missing data is to be added. * @param probs The probability of adding missing data to each column. * @return The new data sets with missing data added. */ public static DataSet addMissingData(DataSet inData, double[] probs) { DataSet outData; try { outData = (DataSet) new MarshalledObject(inData).get(); } catch (Exception e) { throw new RuntimeException(e); } if (probs.length != outData.getNumColumns()) { throw new IllegalArgumentException("Wrong number of elements in prob array"); } for (double prob : probs) { if (prob < 0.0 || prob > 1.0) { throw new IllegalArgumentException("Probability out of range"); } } for (int j = 0; j < outData.getNumColumns(); j++) { Node variable = outData.getVariable(j); for (int i = 0; i < outData.getNumRows(); i++) { double test = RandomUtil.getInstance().nextDouble(); if (test < probs[j]) { outData.setObject(i, j, ((Variable) variable).getMissingValueMarker()); } } } return outData; }
From source file:edu.cmu.tetrad.data.DataUtils.java
public static DataSet replaceMissingWithRandom(DataSet inData) { DataSet outData;//from w w w . j a va 2 s . c om try { outData = (DataSet) new MarshalledObject(inData).get(); } catch (Exception e) { throw new RuntimeException(e); } for (int j = 0; j < outData.getNumColumns(); j++) { Node variable = outData.getVariable(j); if (variable instanceof DiscreteVariable) { List<Integer> values = new ArrayList<Integer>(); for (int i = 0; i < outData.getNumRows(); i++) { int value = outData.getInt(i, j); if (value == -99) continue; values.add(value); } Collections.sort(values); for (int i = 0; i < outData.getNumRows(); i++) { if (outData.getInt(i, j) == -99) { int value = RandomUtil.getInstance().nextInt(values.size()); outData.setInt(i, j, values.get(value)); } } } else { double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; for (int i = 0; i < outData.getNumRows(); i++) { double value = outData.getDouble(i, j); if (value < min) min = value; if (value > max) max = value; } for (int i = 0; i < outData.getNumRows(); i++) { double random = RandomUtil.getInstance().nextDouble(); outData.setDouble(i, j, min + random * (max - min)); } } } return outData; }
From source file:edu.cmu.tetrad.sem.SemIm.java
/** * Copy constructor.//w w w .j a v a2 s .co m * * @throws RuntimeException if the given SemIm cannot be serialized and * deserialized correctly. */ public SemIm(SemIm semIm) { try { // We make a deep copy of semIm and then copy all of its fields // into this SEM IM. Otherwise, it's just too HARD to make a deep copy! // (Complain, complain.) jdramsey 4/20/2005 SemIm _semIm = (SemIm) new MarshalledObject(semIm).get(); semPm = _semIm.semPm; variableNodes = _semIm.variableNodes; measuredNodes = _semIm.measuredNodes; freeParameters = _semIm.freeParameters; fixedParameters = _semIm.fixedParameters; meanParameters = _semIm.meanParameters; edgeCoef = _semIm.edgeCoef; errCovar = _semIm.errCovar; variableMeans = _semIm.variableMeans; variableMeansStdDev = _semIm.variableMeansStdDev; sampleCovarC = _semIm.sampleCovarC; sampleSize = _semIm.sampleSize; implCovar = _semIm.implCovar; implCovarMeasC = _semIm.implCovarMeasC; freeMappings = _semIm.freeMappings; fixedMappings = _semIm.fixedMappings; standardErrors = _semIm.standardErrors; parameterBoundsEnforced = _semIm.parameterBoundsEnforced; estimated = _semIm.estimated; cyclic = _semIm.cyclic; distributions = new HashMap<Node, Distribution>(_semIm.distributions); scoreType = _semIm.scoreType; } catch (IOException e) { throw new RuntimeException("SemIm could not be deep cloned.", e); } catch (ClassNotFoundException e) { throw new RuntimeException("SemIm could not be deep cloned.", e); } }
From source file:edu.cmu.tetrad.search.TestHippocampus.java
public void test1a() { String[] fakeNames = { "PRC", "PHC", "ENT", "CA32DG", "CA1", "SUB" }; Map<String, Node> roiNodes = new LinkedHashMap<String, Node>(); for (String name : fakeNames) { roiNodes.put(name, new ContinuousVariable(name)); }//from www.ja v a 2 s .c om String graph = "PRC-->ENT1,PNC-->ENT1,ENT1-->DG,DG-->CA3,CA3-->CA2,CA2-->CA2P,CA2P-->CA1," + "CA1-->SUB,SUB-->ENT2"; int v = 50; int[][] trueVoxellation = constructRois(1, v, v, v, v, v, v, v, v, v, v, 0); String[] trueNames = { "PRC", "PHC", "ENT1", "DG", "CA3", "CA2", "CA2P", "CA1", "SUB", "ENT2", "OTHER" }; int[][] fakeVoxellations; fakeVoxellations = move(trueNames, trueVoxellation, v, "", "A"); Graph g = GraphUtils.randomDag(100, 100, false); try { Graph g2 = (Graph) new MarshalledObject(g).get(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.openspaces.pu.container.servicegrid.deploy.Deploy.java
private OperationalString loadDeployment(String puString, String codeserver, SLA sla, String puPath, String puName, BeanLevelProperties beanLevelProperties, Map<String, String> elasticProperties, RequiredDependencies deploymentRequiredDependencies, RequiredDependencies startRequiredDependencies, String applicationName) throws Exception { InputStream opstringURL = Deploy.class .getResourceAsStream("/org/openspaces/pu/container/servicegrid/puservicebean.xml"); OperationalString opString;/*w w w.j a va 2s .c o m*/ //load the servicebean opstring OpStringLoader opStringLoader = new OpStringLoader(); opStringLoader.setDefaultGroups(getGroups()); opStringLoader.setDefaultLookupLocators(getLocators()); opStringLoader.setCodebaseOverride(codeserver); opString = opStringLoader.parseOperationalString(opstringURL)[0]; ((OpString) opString).setName(puName); //this opstring should only have one servicebean ServiceElement[] serviceElements = opString.getServices(); ServiceElement element = serviceElements[0]; //put the entire pu spring xml as parameter to servicebean element.getServiceBeanConfig().addInitParameter("pu", puString); if (beanLevelProperties != null) { element.getServiceBeanConfig().addInitParameter("pu.type", beanLevelProperties.getContextProperties().remove("pu.type")); element.getServiceBeanConfig().addInitParameter("beanLevelProperties", new MarshalledObject<BeanLevelProperties>(beanLevelProperties)); element.getServiceBeanConfig().addInitParameter( JeeProcessingUnitContainerProvider.JEE_CONTAINER_PROPERTY_NAME, JeeProcessingUnitContainerProvider.getJeeContainer(beanLevelProperties)); } //sla int numberOfInstances = sla.getNumberOfInstances(); int numberOfBackups = sla.getNumberOfBackups(); Policy policy = sla.getPolicy(); if (policy != null) { String type; if (policy instanceof ScaleUpPolicy) { type = "scaling"; } else if (policy instanceof RelocationPolicy) { type = "relocation"; } else { throw new IllegalArgumentException("Unknown SLA Policy:" + policy); } String max = String.valueOf(sla.getNumberOfInstances()); //todo: make sure max is greater then num of instances if (policy instanceof ScaleUpPolicy) { max = String.valueOf(((ScaleUpPolicy) policy).getMaxInstances()); numberOfInstances = ((ScaleUpPolicy) policy).getMaxInstances(); } String[] configParms = getSLAConfigArgs(type, max, policy.getLowerDampener(), policy.getUpperDampener()); org.jini.rio.core.SLA slaElement = new org.jini.rio.core.SLA(policy.getMonitor(), new double[] { policy.getLow(), policy.getHigh() }, configParms, null); element.getServiceLevelAgreements().addServiceSLA(slaElement); } //requirements applyRequirements(element, sla.getRequirements()); element.getFaultDetectionHandlerBundle().addMethod("setConfiguration", new Object[] { new String[] { "-", "org.openspaces.pu.container.servicegrid.PUFaultDetectionHandler.invocationDelay = " + sla.getMemberAliveIndicator().getInvocationDelay(), "org.openspaces.pu.container.servicegrid.PUFaultDetectionHandler.retryCount = " + sla.getMemberAliveIndicator().getRetryCount(), "org.openspaces.pu.container.servicegrid.PUFaultDetectionHandler.retryTimeout = " + sla.getMemberAliveIndicator().getRetryTimeout() } }); if (sla.getMaxInstancesPerVM() > 0) { element.setMaxPerMachine(sla.getMaxInstancesPerVM()); } if (sla.getMaxInstancesPerMachine() > 0) { element.setMaxPerPhysicalMachine(sla.getMaxInstancesPerMachine()); } element.setRequiresIsolation(sla.isRequiresIsolation()); element.setMaxPerZone(sla.getMaxInstancesPerZone()); element.setElasticProperties(elasticProperties); element.setInstanceDeploymentDependencies(deploymentRequiredDependencies); element.setInstanceStartDependencies(startRequiredDependencies); element.setApplicationName(applicationName); element.setTotalNumberOfServices(sla.getNumberOfInstances()); // set for each service to have the operation string name element.getServiceBeanConfig().setName(element.getOperationalStringName().replace(' ', '-')); // pass the SLA as an init parameter so the GSC won't need to parse the XML again element.getServiceBeanConfig().addInitParameter("sla", new MarshalledObject<SLA>(sla)); element.getServiceBeanConfig().addInitParameter("numberOfInstances", numberOfInstances); element.getServiceBeanConfig().addInitParameter("numberOfBackups", numberOfBackups); // add pu names, path and code server so it can be used on the service bean side element.getServiceBeanConfig().addInitParameter("puName", puName); element.getServiceBeanConfig().addInitParameter("puPath", puPath); element.getServiceBeanConfig().addInitParameter("primaryZone", sla.getPrimaryZone()); //this is the MOST IMPORTANT part if (sla.getInstanceSLAs() != null && sla.getInstanceSLAs().size() > 0) { element.setPlanned(1); String name = element.getName(); opString.removeService(element); for (int instanceId = 1; instanceId <= sla.getNumberOfInstances(); instanceId++) { ServiceElement clone = deepCopy(element); clone.getServiceBeanConfig().setName(name + "." + instanceId); clone.getServiceBeanConfig().addInitParameter("clusterGroup", String.valueOf(instanceId)); clone.getServiceBeanConfig().addInitParameter("instanceId", String.valueOf(instanceId)); InstanceSLA instanceSLA = findInstanceSLA(instanceId, null, sla.getInstanceSLAs()); if (instanceSLA != null) { applyRequirements(clone, instanceSLA.getRequirements()); } opString.addService(clone); if (logger.isTraceEnabled()) { logger.trace("Using Service Element " + element.toString()); } for (int backupId = 1; backupId <= sla.getNumberOfBackups(); backupId++) { clone = deepCopy(element); clone.getServiceBeanConfig().setName(name + "." + instanceId + "_" + backupId); clone.getServiceBeanConfig().addInitParameter("clusterGroup", String.valueOf(instanceId)); clone.getServiceBeanConfig().addInitParameter("instanceId", String.valueOf(instanceId)); clone.getServiceBeanConfig().addInitParameter("backupId", String.valueOf(backupId)); instanceSLA = findInstanceSLA(instanceId, backupId, sla.getInstanceSLAs()); if (instanceSLA != null) { applyRequirements(clone, instanceSLA.getRequirements()); } opString.addService(clone); if (logger.isTraceEnabled()) { logger.trace("Using Service Element " + element.toString()); } } } } else { boolean hasBackups = sla.getNumberOfBackups() > 0; if (hasBackups) { //the extra one is the primary element.setPlanned(sla.getNumberOfBackups() + 1); String name = element.getName(); opString.removeService(element); for (int i = 1; i <= sla.getNumberOfInstances(); i++) { ServiceElement clone = deepCopy(element); clone.getServiceBeanConfig().setName(name + "." + i); clone.getServiceBeanConfig().addInitParameter("clusterGroup", String.valueOf(i)); opString.addService(clone); if (logger.isTraceEnabled()) { logger.trace("Using Service Element " + element.toString()); } } } else { element.setPlanned(sla.getNumberOfInstances()); element.getServiceBeanConfig().addInitParameter("clusterGroup", String.valueOf(1)); if (logger.isTraceEnabled()) { logger.trace("Using Service Element " + element.toString()); } } } return (opString); }
From source file:org.taverna.server.master.localworker.RemoteRunDelegate.java
private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject();//w ww. ja va2 s. c o m out.writeUTF(secContext.getOwner().getName()); out.writeObject(secContext.getFactory()); out.writeObject(new MarshalledObject<RemoteSingleRun>(run)); }
From source file:org.taverna.server.master.worker.RemoteRunDelegate.java
private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject();//from w w w . j av a 2s . com out.writeUTF(secContext.getOwner().getName()); out.writeObject(secContext.getFactory()); out.writeObject(new MarshalledObject<>(run)); }