Command Layer Definition

Command layer contains mechanism to make Cytoscape functions easily accessible from application layer. This layer should be separated from application layer and can be used in any mode: Desktop application, server version, and command line version.


Command Usecases

(Not finished yet...)

Multiple Language Support

Commands should be easily accessible from dynamic (scripting) languages, including Python, Ruby, and JavaScript. This will be implemented using scripting language engins running on JVM (Jruby, Rhino, and Jython). This enables users to write simple tasks as scripts.

Functions Encapsulated as Command

In general, most of the classes in cytoscape.actions will be converted into Commands. In addition, some of the methods under the class cytoscape.Cytoscape will be encapsulated as command. Such as:


How to Call Commands

   1 // Java
   2 Command c = CommandService.getCommand("command_name");
   3 Object result = c.execute( parameters );
   5 // Ruby
   6 c = CommandService.getCommand("command_name")
   7 result = c.execute( parameters )

We can implement similar functions Felix ShellService has:

   1 package;
   3 public interface ShellService
   4 {
   5     public String[] getCommands();
   6     public String getCommandUsage(String name);
   7     public String getCommandDescription(String name);
   8     public ServiceReference getCommandReference(String name);
   9     public void executeCommand(
  10         String commandLine, PrintStream out, PrintStream err)
  11         throws Exception;
  12 }

Like other layers, Command Layer will be distributed as a bundle. This bundle consists of the following:

  1. Command interface: All commands should implement this interface.
  2. Command Service Manager: (will be discussed in the next section)

Because Command implementations will be services, any bundle (or plugin) will be able to make Command services available. There will likely be a one or two bundles that provide the bulk to the Commands that constitute the core of Cytoscape including Command like loadNetwork(), etc.. Any plugin writing a command will depend on the Command bundle.

Command Service Manager

Command Service Manager is a simple utility class to make all commands easily accessible from all parts of Cytoscape. Essentially, this is a custom version of ServiceTracker class. Since all commands are registered as OSGi services, command users access commands through OSGi service mechanism. However, it is better to wrap this with a simple API to hide the detail of the OSGi service mechanism. The CommandServiceManager API will be something like the following:

   1 public class CommandServiceManager {
   2     public static Command getCommand(String command_name) {}
   3     public static List<String> getAvailableCommand() {}
   4 }

This class is only for accessing (using) commands. Developers should register command implementations like other OSGi services (can be done with Spring-DM). Each command have a OSGi Service Property to represent that it is a Cytoscape command. This property will be used by the service tracker to filtering services.


All commands should implement the following interface:

   1 public interface Command {
   2         // Getters
   3         public String getName();
   4         public String getDescription();
   6        // support for Tunables here...
   8         // Execute the command.
   9         public void execute() throws Exception;
  10 }

Because Commands will all require different inputs to function there is no way to capture this using a single interface. For example, a LayoutNetworkView command will need two parameters a LayoutAlgorithm and a NetworkView to operate. Rather than configuring the Command interface to support networks and layout algorithms, we need a general mechanism for specifying input parameters. We propose that Tunables will be the mechanism for specifying Command parameters. In 2.6, Tunable was a class that stores parameter values and provides mechanisms for a user interface to be inferred from the parameter value. Tunables will be refactored in version 3.0 to address a few design deficiencies. Tunables are discussed extensively Cytoscape 3.0/TunableDiscussion here. Whatever the final Tunable mechanism looks like, this is what we will use for specifying parameters to Commands.

Open Questions

Commands with Dependency Injection Framework

With Spring Framework, the command layer will looks like the following:

One of the advantages to use DI container is simpler integration test code.

   1 @RunWith(SpringJUnit4ClassRunner.class)
   2 @ContextConfiguration(locations={"/META-INF/spring/bundle-context.xml"})
   3 public class ExampleBeanIntegrationTest extends
   4                 AbstractDependencyInjectionSpringContextTests {
   6         @Autowired
   7         private ImportGraphFileCommand command1;
   9         @Autowired
  10         private LayoutCommand command2;
  12         ...
  14         @Test
  15         public void testWorkflow() throws Exception {
  16                 List<Object> parameter = new ArrayList<Object>();
  17                 List<Class<?>> parameterType = new ArrayList<Class<?>>();
  19                 parameter.add("testData/galFiltered.sif");
  20                 parameterType.add(String.class);
  22                 List<Object> result = command1.execute(parameter, parameterType);
  24                 //Do something with other commands
  26         }
  27 }

Commad Implemented with Dynamic Languages

From Spring 2.5, it has a built-in support for dynamic languages. By using this feature, developers can implement commands with other languages and make it available other developers.

And Command Service Manager will be a class that holds an OSGi ServiceTracker:

   1 public final class CommandManager implements BundleActivator {
   3         private ServiceTracker commandServiceTracker;
   5         public Command getCommand(final String commandName){
   6             //returns the command using Service Tracker
   7         }
   9         public void start(BundleContext bundleContext) throws Exception {
  10                 commandServiceTracker = new ServiceTracker(bundleContext, Command.class
  11                                 .getName(), null) {
  12                         @Override
  13                         public Command addingService(ServiceReference serviceReference) {
  14                                 Command command = (Command) super.addingService(serviceReference);
  15                                 return command;
  16                         }
  17                 };
  19       ;
  21         }
  23         public void stop(BundleContext bundleContext) throws Exception {
  24                 commandServiceTracker.close();
  25         }
  26 }

OSGi Service


Dynamic Language Support on JVM

Outdated_Cytoscape_3.0/CommandDiscussions (last edited 2011-02-24 15:33:09 by PietMolenaar)

Funding for Cytoscape is provided by a federal grant from the U.S. National Institute of General Medical Sciences (NIGMS) of the Na tional Institutes of Health (NIH) under award number GM070743-01. Corporate funding is provided through a contract from Unilever PLC.

MoinMoin Appliance - Powered by TurnKey Linux