Search

13.4.3. Object State Viewers (OSV)

download PDF
When an object is selected in the Objects pane of the main window, the registered Object State Viewer (OSV) for the object's type is invoked. An OSV makes information about the selected object available via the user interface. An OSV for Atomic Actions (transactions) is distributed with the standard tools. It displays information on the Abstract Records in its lists of methods, such as heuristic, failed, read-only, and others. You can write your own OSVs to display information about object types you have defined.

13.4.3.1. Writing an OSV

You can write an OSV plug-in so that the Object Store browser can show the state of user-defined abstract records. An OSV plug-in is a class which implements the com.arjuna.ats.tools.objectstorebrowser.stateviewers.StateViewerInterface interface.
It must be packaged in a JAR within the plugins/ directory. The example at Example 13.1, “AbstractRecord Class” creates an OSV plugin for the AbstractRecord class.

Example 13.1. AbstractRecord Class

	  public class SimpleRecord extends AbstractRecord
	  {
	  private int _value = 0;
	  
	  .....
	  
	  public void increase()
	  {
	  _value++;
	  }
	  
	  public int get()
	  {
	  return _value;
	  }
	  
	  public String type()
	  {
	  return “/StateManager/AbstractRecord/SimpleRecord”;
	  }
	  
	  public boolean restore_state(InputObjectState os, int i)
	  {
	  boolean returnValue = true;
	  
	  try
	  {
	  _value = os.unpackInt();
	  }
	  catch (java.io.IOException e)
	  {
	  returnValue = false;
	  }
	  
	  return returnValue;
	  }
	  
	  public boolean save_state(OutputObjectState os, int i)
	  {
	  boolean returnValue = true;
	  
	  try
	  {
	  os.packInt(_value);
	  }
	  catch (java.io.IOException e)
	  {
	  returnValue = false;
	  }
	  
	  return returnValue;
	  }
	  }
The goal is to show the current value of the abstract record when it is viewed in the object store browser. You can read the state into an instance of your abstract record, and call the getValue() method to accomplish this easily.
	  public class SimpleRecordOSVPlugin implements StateViewerInterface
	  {
	  /**
	  * A uid node of the type this viewer is registered against has been expanded.
	  * @param os
	  * @param type
	  * @param manipulator
	  * @param node
	  * @throws ObjectStoreException
	  */
	  public void uidNodeExpanded(ObjectStore os,
	  String type,
	  ObjectStoreBrowserTreeManipulationInterface 
	  manipulator,
	  UidNode node,
	  StatePanel infoPanel)
	  throws ObjectStoreException
	  {
	  // Do nothing
	  }
	  
	  /**
	  * An entry has been selected of the type this viewer is registered against.
	  *
	  * @param os
	  * @param type
	  * @param uid
	  * @param entry
	  * @param statePanel
	  * @throws ObjectStoreException
	  */
	  public void entrySelected(ObjectStore os,
	  String type,
	  Uid uid,
	  ObjectStoreViewEntry entry,
	  StatePanel statePanel) 
	  throws ObjectStoreException
	  {
	  SimpleRecord rec = new SimpleRecord();
	  
	  if ( rec.restore_state( os.read_committed(uid, type), ObjectType.ANDPERSISTENT ) )
	  {
	  statePanel.setData( “Value”, rec.getValue() );
	  }
	  }
	  
	  /**
	  * Get the type this state viewer is intended to be registered against.
	  * @return
	  */
	  public String getType()
	  {
	  return “/StateManager/AbstractRecord/SimpleRecord”;
	  }
	  }
The uidNodeExpanded method is invoked when a Unique Identification (UID) representing the given type is expanded in the object store hierarchy tree. This abstract record is not visible in the object store directly. It is only viewable via one of the lists in an atomic action. The entrySelected method is invoked when an entry is selected from the Object view, which represents an object with the given type. In both methods, the StatePanel is used to display information regarding the state of the object. The StatePanel includes the methods listed in StatePanel Methods to assist in display this information.

StatePanel Methods

setInfo(String info)
Shows general information.
setData(String name, String value)
Puts information into the table which is displayed by the object store browser tool.
enableDetailsButton(DetailsButtonListener listener)
Enable the Details button. The listener interface allows a plug-in to be informed when the button is pressed. You, as the developer, control how to display this information.
In this example, the state is read from the object store and the value returned by the getValue() method is used to put an entry into the state panel table. The getType() method returns the type of this plug-in for registration.
To add this plug-in to the object store browser, package it into a JAR file with a name that is prefixed with osbv-. The JAR file must contain certain information within the manifest file, to inform the object store browser which classes are plug-ins. Refer to Example 13.2, “Packing the Plug-In with Ant” to do this using an Apache Ant script.

Example 13.2. Packing the Plug-In with Ant

	  <jar jarfile="osbv-simplerecord.jar">
	  <fileset dir="build" includes="*.class”/>
	  <manifest>
	  <section name="arjuna-tools-objectstorebrowser">
	  <attribute name="plugin-classname-1" value=" SimpleRecordOSVPlugin "/>
	  </section>
	  </manifest>
	  </jar>
After you have created the JAR with the correct information in the manifest file, place it in the bin/tools/plugins directory.
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.