Search in sources :

Example 1 with ItemPath

use of org.cristalise.kernel.lookup.ItemPath in project kernel by cristal-ise.

the class AgentImplementation method refreshJobList.

/**
 * Updates an Agent's list of Jobs relating to a particular activity. Only
 * Activities that are assigned to a Role that is flagged to push Jobs do this.
 */
@Override
public synchronized void refreshJobList(SystemKey sysKey, String stepPath, String newJobs) {
    try {
        ItemPath itemPath = new ItemPath(sysKey);
        JobArrayList newJobList = (JobArrayList) Gateway.getMarshaller().unmarshall(newJobs);
        List<String> keysToRemove = currentJobs.getKeysForStep(itemPath, stepPath);
        // merge new jobs in first, so the RemoteMap.getLastId() used during addJob() returns the next unique id
        for (Job newJob : newJobList.list) {
            Logger.msg(6, "AgentImplementation.refreshJobList() - Adding job:" + newJob.getItemPath() + "/" + newJob.getStepPath() + ":" + newJob.getTransition().getName());
            currentJobs.addJob(newJob);
        }
        // remove old jobs for this item0
        for (String key : keysToRemove) currentJobs.remove(key);
        Gateway.getStorage().commit(mItemPath);
    } catch (Throwable ex) {
        Logger.error("Could not refresh job list.");
        Logger.error(ex);
        Gateway.getStorage().abort(mItemPath);
    }
}
Also used : ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 2 with ItemPath

use of org.cristalise.kernel.lookup.ItemPath in project kernel by cristal-ise.

the class AgentProxy method searchItem.

/**
 * Let scripts resolve items
 */
public ItemProxy searchItem(Path root, String name) throws ObjectNotFoundException {
    Iterator<Path> results = Gateway.getLookup().search(root, name);
    Path returnPath = null;
    if (!results.hasNext()) {
        throw new ObjectNotFoundException(name);
    } else {
        while (results.hasNext()) {
            Path nextMatch = results.next();
            if (returnPath != null) {
                // found already one but search if there are another, which is an error
                if (isItemPathAndNotNull(nextMatch)) {
                    // test if another itemPath with same name
                    if (!returnPath.getItemPath().getUUID().equals(nextMatch.getItemPath().getUUID())) {
                        throw new ObjectNotFoundException("Too many different items with name:" + name);
                    } else {
                        returnPath = nextMatch;
                    }
                }
            } else {
                if (isItemPathAndNotNull(nextMatch)) {
                    returnPath = nextMatch;
                    // found one but continue search
                    Logger.msg(5, "AgentProxy.searchItem() - found for " + name + " UUID = " + returnPath.getItemPath().getUUID());
                }
            }
        }
    }
    // test if nothing found in the results
    if (returnPath == null) {
        throw new ObjectNotFoundException(name);
    }
    return Gateway.getProxyManager().getProxy(returnPath);
}
Also used : ItemPath(org.cristalise.kernel.lookup.ItemPath) RolePath(org.cristalise.kernel.lookup.RolePath) DomainPath(org.cristalise.kernel.lookup.DomainPath) AgentPath(org.cristalise.kernel.lookup.AgentPath) Path(org.cristalise.kernel.lookup.Path) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException)

Example 3 with ItemPath

use of org.cristalise.kernel.lookup.ItemPath in project kernel by cristal-ise.

the class ProxyClientConnection method setSocket.

@Override
public synchronized void setSocket(Socket newSocket) {
    try {
        Logger.msg(1, "ProxyClientConnection.setSocket() - clientID " + thisClientId + " connect from " + newSocket.getInetAddress() + ":" + newSocket.getPort());
        newSocket.setSoTimeout(500);
        clientSocket = newSocket;
        response = new PrintWriter(clientSocket.getOutputStream(), true);
        subscribedItems = new ArrayList<ItemPath>();
    } catch (SocketException ex) {
        Logger.error("ProxyClientConnection.setSocket() - Could not set socket timeout:");
        Logger.error(ex);
        closeSocket();
    } catch (IOException ex) {
        Logger.error("ProxyClientConnection.setSocket() - Could not setup output stream:");
        Logger.error(ex);
        closeSocket();
    }
}
Also used : SocketException(java.net.SocketException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) PrintWriter(java.io.PrintWriter) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 4 with ItemPath

use of org.cristalise.kernel.lookup.ItemPath in project kernel by cristal-ise.

the class ProxyClientConnection method sendMessage.

public synchronized void sendMessage(ProxyMessage message) {
    // idle
    if (clientSocket == null)
        return;
    boolean relevant = message.getItemPath() == null;
    synchronized (subscribedItems) {
        for (Iterator<ItemPath> iter = subscribedItems.iterator(); iter.hasNext() && !relevant; ) {
            ItemPath thisKey = iter.next();
            if (thisKey.equals(message.getItemPath()))
                relevant = true;
        }
    }
    // not for our client
    if (!relevant)
        return;
    response.println(message);
}
Also used : ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 5 with ItemPath

use of org.cristalise.kernel.lookup.ItemPath in project kernel by cristal-ise.

the class ImportAggregation method create.

public org.cristalise.kernel.collection.Aggregation create() throws InvalidCollectionModification, ObjectNotFoundException, ObjectAlreadyExistsException {
    Aggregation newAgg = isDescription ? new AggregationDescription(name) : new AggregationInstance(name);
    if (version != null)
        newAgg.setVersion(version);
    for (ImportAggregationMember thisMem : aggregationMemberList) {
        StringBuffer classProps = new StringBuffer();
        ItemPath itemPath = null;
        if (thisMem.itemDescriptionPath != null && thisMem.itemDescriptionPath.length() > 0) {
            try {
                itemPath = new ItemPath(thisMem.itemDescriptionPath);
            } catch (InvalidItemPathException ex) {
                itemPath = new DomainPath(thisMem.itemDescriptionPath).getItemPath();
            }
            String descVer = thisMem.itemDescriptionVersion == null ? "last" : thisMem.itemDescriptionVersion;
            PropertyDescriptionList propList = PropertyUtility.getPropertyDescriptionOutcome(itemPath, descVer, null);
            for (PropertyDescription pd : propList.list) {
                thisMem.props.put(pd.getName(), pd.getDefaultValue());
                if (pd.getIsClassIdentifier())
                    classProps.append((classProps.length() > 0 ? "," : "")).append(pd.getName());
            }
        }
        if (thisMem.itemPath != null && thisMem.itemPath.length() > 0) {
            try {
                itemPath = new ItemPath(thisMem.itemPath);
            } catch (InvalidItemPathException ex) {
                itemPath = new DomainPath(thisMem.itemPath).getItemPath();
            }
        }
        newAgg.addMember(itemPath, thisMem.props, classProps.toString(), new GraphPoint(thisMem.geometry.x, thisMem.geometry.y), thisMem.geometry.width, thisMem.geometry.height);
    }
    return newAgg;
}
Also used : Aggregation(org.cristalise.kernel.collection.Aggregation) PropertyDescription(org.cristalise.kernel.property.PropertyDescription) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) AggregationDescription(org.cristalise.kernel.collection.AggregationDescription) GraphPoint(org.cristalise.kernel.graph.model.GraphPoint) AggregationInstance(org.cristalise.kernel.collection.AggregationInstance) PropertyDescriptionList(org.cristalise.kernel.property.PropertyDescriptionList) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Aggregations

ItemPath (org.cristalise.kernel.lookup.ItemPath)36 DomainPath (org.cristalise.kernel.lookup.DomainPath)16 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)14 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)10 PersistencyException (org.cristalise.kernel.common.PersistencyException)10 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)10 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)6 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)5 CannotManageException (org.cristalise.kernel.common.CannotManageException)4 AgentPath (org.cristalise.kernel.lookup.AgentPath)4 Test (org.junit.Test)4 Aggregation (org.cristalise.kernel.collection.Aggregation)3 TraceableEntity (org.cristalise.kernel.entity.TraceableEntity)3 Path (org.cristalise.kernel.lookup.Path)3 Property (org.cristalise.kernel.property.Property)3 PropertyDescription (org.cristalise.kernel.property.PropertyDescription)3 PropertyDescriptionList (org.cristalise.kernel.property.PropertyDescriptionList)3 ConcurrentModificationException (java.util.ConcurrentModificationException)2 StringTokenizer (java.util.StringTokenizer)2 Dependency (org.cristalise.kernel.collection.Dependency)2