Share and version Java entities with EMF and EMFStore

Tutorial - EMFStore - A Model Repository - Part 2

          

The API

In the section „Try it!”, we describe the most important use cases based on an extensible example client. However, EMFStore can also be used independently of the example client and can be integrated into existing applications. To show you how we do this, we'll describe some examples from the EMFStore API. Check out detailed documentation of the EMFStore API to find out more about it.

Projects on the client are managed in a Workspace that allows you to access and create projects. A project is managed by a ProjectSpace whose entities contain meta-information, such as the name of a project or tracked changes. The following code example retrieves the current workspace and creates a new local project:

Workspace workspace = WorkspaceManager.getInstance().getCurrentWorkspace();
ProjectSpace projectSpace = workspace.createLocalProject("ProjectName", "Project Description");

The next step is to fill the local project with model entities. In EMF, entities are structured by a containment hierarchy (see earlier tutorial example). The following call adds a new entity into a project:

projectSpace.getProject().getModelElements().add(myEntity);

Regular changes on the entities are made using the getter and setter methods, making EMFStore transparent for the client. If new entities are added to other entities, they are automatically added to the project as well. The following code example changes an entity's attribute and adds a new entity to another one.

myEntity.setName(“xxx”);
myEntity.getChildren().add(newObject);

The project created is only locally available, but with the following code example, it is shared with the EMFStore server and therefore available for other clients. To manage the connection with the EMFStore server a UserSession is created, containing credentials for access control, the server address and port.

Usersession usersession = EMFStoreClientUtil.createUsersession("super", "super",
 "localhost", 8080);
projectSpace.shareProject(usersession);

Once a project is shared on the EMFStore server, it can be retrieved by other clients via checkout. In this case, the user usually selects from a list of available projects retrieved from the server. The following code example retrieves the list of available projects and selects the first one for check-out.

List<ProjectInfo> projectList =
workspace.getRemoteProjectList(usersession);
workspace.checkout(usersession, projectList.get(0));

Once projects are shared on multiple clients, changes can be synchronized. The first step is to apply changes to the model entities, e.g. someElement.setName(„newName“). These changes are automatically recorded and can be sent to the EMFStore server:

projectSpace.commit(logMessage, null, new ConsoleProgressMonitor()); 

In turn, changes can be retrieved from the server triggering an update:

projectSpace.update();

Using the features share, checkout, commit and update allows you to create a custom client which synchronizes its data (model entities) through the EMFStore server. The API offers many additional features such as retrieving a list of current changes or resetting the state of a project to a specific version.

Conclusion

The EMFStore model repository is a runtime technology that enables you to collaboratively modify EMF model entities. Using an example client provided by the EMF Client Platform, it assists in testing the most important use cases. In contrast with existing Source Code Management Systems, the EMFStore model repository does not work directly on files, but instead versions entities on a model level. This enables precise conflict detection for EMF model entities as well as interactive merging. All features of the EMFStore can also be triggered via an API. This allows the integration of EMFStore into custom clients, with or without a UI. EMFStore is an open source framework (Eclipse Public License). Source code, releases and documentation are all available online.

Pages

Maximilian Koegel
Maximilian Koegel
Jonas  Helming
Jonas Helming

What do you think?

JAX Magazine - 2014 - 03 Exclucively for iPad users JAX Magazine on Android

Comments

Latest opinions