public class Workspace
extends java.lang.Object
SimbrainDesktop
.Coupling
Constructor and Description |
---|
Workspace()
Construct a workspace.
|
Modifier and Type | Method and Description |
---|---|
void |
addCoupling(Coupling<?> coupling)
Adds a coupling to the CouplingManager.
|
void |
addListener(WorkspaceListener listener)
Adds a listener to the workspace.
|
void |
addUpdateAction(UpdateAction action)
Convenience method for adding an update action to the workspace's action
list (the sequence of actions invoked on each iteration of the
workspace).
|
void |
addWorkspaceComponent(WorkspaceComponent component)
Adds a workspace component to the workspace.
|
boolean |
changesExist()
Check whether there have been changes in the workspace or its components.
|
void |
clearWorkspace()
Remove all components (networks, worlds, etc.) from this workspace.
|
void |
coupleOneToMany(java.util.List<PotentialProducer> sourceAttributes,
java.util.List<PotentialConsumer> targetAttributes)
Couple each source attribute to all target attributes.
|
void |
coupleOneToOne(java.util.List<PotentialProducer> producerKeys,
java.util.List<PotentialConsumer> consumerKeys)
Couple each source attribute to one target attribute, as long as there
are target attributes to couple to.
|
WorkspaceComponent |
getComponent(java.lang.String id)
Get a component using its name id.
|
java.util.List<? extends WorkspaceComponent> |
getComponentList() |
java.util.Collection<? extends WorkspaceComponent> |
getComponentList(java.lang.Class<?> componentType)
Returns all components of the specified type, e.g.
|
Coupling<?> |
getCoupling(java.lang.String id)
Returns the coupling associated with a string id.
|
CouplingManager |
getCouplingManager()
Returns the coupling manager for this workspace.
|
java.lang.String |
getCurrentDirectory() |
java.io.File |
getCurrentFile() |
protected int |
getSavedTime() |
int |
getTime()
Returns global time.
|
int |
getUpdateDelay() |
WorkspaceUpdater |
getUpdater()
Returns a reference to the workspace updater.
|
void |
iterate()
Update the workspace a single time.
|
void |
iterate(java.util.concurrent.CountDownLatch latch)
Iterate using a latch, which is counted down after the iteration
completes.
|
void |
iterate(java.util.concurrent.CountDownLatch latch,
int numIterations)
Iterated for a specified number of iterations using a latch.
|
void |
iterate(int numIterations)
Iterate for a specified number of steps.
|
void |
openWorkspace(java.io.File theFile)
Open a workspace from a file.
|
(package private) void |
preSerializationInit()
Actions required prior to proper serialization.
|
void |
removeAllComponents()
Disposes all Simbrain Windows.
|
void |
removeCoupling(Coupling<?> coupling)
Removes a coupling from the CouplingManager.
|
void |
removeListener(WorkspaceListener listener)
Removes the listener from the workspace.
|
void |
removeWorkspaceComponent(WorkspaceComponent component)
Remove the specified component.
|
void |
resetTime()
Reset time.
|
void |
run()
Iterates all couplings on all components until halted by user.
|
void |
setCurrentDirectory(java.lang.String currentDirectory) |
void |
setCurrentFile(java.io.File currentFile) |
void |
setTaskSynchronizationManager(TaskSynchronizationManager manager)
Set the task synchronization manager.
|
void |
setUpdateDelay(int updateDelay) |
void |
setWorkspaceChanged(boolean workspaceChanged)
Sets whether the workspace has been changed.
|
void |
stop()
Stops iteration of all couplings on all components.
|
<E> E |
syncOnAllComponents(java.util.concurrent.Callable<E> task)
Synchronizes on all components and executes task, returning the result of
that callable.
|
static <E> E |
syncRest(java.util.Iterator<? extends java.lang.Object> iterator,
java.util.concurrent.Callable<E> task)
Recursively synchronizes on the components in the provided iterator and
executes the provided task if there are no more components.
|
java.lang.String |
toString() |
(package private) void |
updateStopped()
Should be called when updating is stopped.
|
public void addListener(WorkspaceListener listener)
listener
- the Listener to add.public void removeListener(WorkspaceListener listener)
listener
- The listener to remove.public void coupleOneToMany(java.util.List<PotentialProducer> sourceAttributes, java.util.List<PotentialConsumer> targetAttributes)
sourceAttributes
- source producing attributestargetAttributes
- target consuming attributespublic void coupleOneToOne(java.util.List<PotentialProducer> producerKeys, java.util.List<PotentialConsumer> consumerKeys) throws UmatchedAttributesException
producerKeys
- source producing attributesconsumerKeys
- target consuming attributesUmatchedAttributesException
public void addWorkspaceComponent(WorkspaceComponent component)
component
- The component to add.public void removeWorkspaceComponent(WorkspaceComponent component)
component
- The component to remove.void updateStopped()
public void iterate()
public void iterate(int numIterations)
numIterations
- number of times to iterate the workspace.public void iterate(java.util.concurrent.CountDownLatch latch, int numIterations)
Executors.newSingleThreadExecutor().execute(new Runnable() { public void run() { // Do one thing CountDownLatch latch = new CountDownLatch(1); workspace.iterate(latch, 100); try { latch.await(); } catch (InterruptedException e) { e.printStackTrace(); } // Do another CountDownLatch latch = new CountDownLatch(1); workspace.iterate(latch, 100); try { latch.await(); } catch (InterruptedException e) { e.printStackTrace(); } } }); }
latch
- the latch to wait onnumIterations
- the number of iteration to run while waiting on the
latchpublic void iterate(java.util.concurrent.CountDownLatch latch)
latch
- the latch to count down after successful iteration.public void run()
public void stop()
public void clearWorkspace()
public void removeAllComponents()
public boolean changesExist()
public void setWorkspaceChanged(boolean workspaceChanged)
workspaceChanged
- Has workspace been changed valuepublic java.lang.String getCurrentDirectory()
public void setCurrentDirectory(java.lang.String currentDirectory)
currentDirectory
- the currentDirectory to setpublic java.io.File getCurrentFile()
public void setCurrentFile(java.io.File currentFile)
currentFile
- The current_file to set.public java.util.List<? extends WorkspaceComponent> getComponentList()
public WorkspaceComponent getComponent(java.lang.String id)
id
- name of componentpublic Coupling<?> getCoupling(java.lang.String id)
id
- the string idpublic void setTaskSynchronizationManager(TaskSynchronizationManager manager)
manager
- public <E> E syncOnAllComponents(java.util.concurrent.Callable<E> task) throws java.lang.Exception
E
- The return type of task.task
- The task to synchronize.java.lang.Exception
- if an exception occurs.public static <E> E syncRest(java.util.Iterator<? extends java.lang.Object> iterator, java.util.concurrent.Callable<E> task) throws java.lang.Exception
E
- The return type of task.iterator
- The iterator of the remaining components to synchronize
on.task
- The task to synchronize.java.lang.Exception
- if an exception occurs.public CouplingManager getCouplingManager()
public java.lang.String toString()
toString
in class java.lang.Object
public void addCoupling(Coupling<?> coupling)
coupling
- The coupling to add.public void removeCoupling(Coupling<?> coupling)
coupling
- The coupling to remove.public java.util.Collection<? extends WorkspaceComponent> getComponentList(java.lang.Class<?> componentType)
componentType
- the type of the component, in the sense of its classpublic int getTime()
protected int getSavedTime()
public void resetTime()
public WorkspaceUpdater getUpdater()
public int getUpdateDelay()
public void setUpdateDelay(int updateDelay)
updateDelay
- the updateDelay to setvoid preSerializationInit()
public void openWorkspace(java.io.File theFile)
theFile
- the file to try to openpublic void addUpdateAction(UpdateAction action)
action
- new action