![]() |
Copyright © TIBCO Software Inc. All Rights Reserved |
The ASPersistence example demonstrates how to implement the external shared-all persistence interface.The ASPersistence example provides two example implementations of the Persister interface.
• The first implementation, SimplePersister, uses an in-memory HashMap as the data store.
• The second implementation, ASPersister, uses a database as the data store.The onWrite method of the persister is invoked when data is put into the space.The onRead method of the persister is invoked when data is read from the data store back into the space.To see data being read back out of the data store, the space needs to be defined with a capacity so that when the capacity is exceeded, the least recently used data in the space is ejected from the space. When data that has been previously ejected from the space is read back into the space, you will see the onRead method of the persister invoked.The ASPersistence examples does not provide the means to read or write data into the space. Therefore, you should run the ASOperations example program along with the ASPersistence example.The following examples show how to invoke ASPersistence for each of the API sets:AS_HOME\examples\dotnet\ASPersistence.exe -metaspace examplems -member_name sharedall -capacity 2 -eviction_policy lru
ASPersistence does not use the default space but uses a basic space definition and sets the persistence type of the space to 'shared-all'. ASPersistence uses a default space name of shared_all_persisted to identify this slightly different space so that you will not get a space definition mismatch with the other examples which may already be running.The following examples indicate how to invoke ASOperations to work in conjunction with the ASPersistence example so that you can see the various methods of the persister being invoked.AS_HOME\examples\dotnet\ASOperations.exe -metaspace examplems -space shared_all_persisted -persistence share_all -capacity 2 -eviction_policy lruThe following example shows the command line options that you can be use when starting ASPersistence to have it join the security domain exdomain:To invoke ASOperations to work in conjunction with the ASPersistence example when it has been started with security, use the following command line options:These command line options start ASPersistence and ASOperations using the default metaspace name ms and allow them to connect to a security domain controller that has been started using the example security policy file example_policy.txt. Using ASPersistence
Because encrypted fields cannot be persisted with shared all persistence, you should not try to use the -encrypt_field command line option when starting ASPersistence or ASOperations for this scenario.Use ASOperations to put the following data into the space:Each time a put is done using ASOperations, you will see the onWrite method of the Persister interface invoked in the command window where the ASPersistence example was started.Since we have defined the space to have a capacity of 2 but we have put three entries into the space, the first entry will be evicted from the space. To verify this, enter br at the command prompt displayed by the ASOperations example and press Enter when prompted for a filter. The last two entries put into the space should be displayed.Now use ASOperations to get the entry with an index of 1 back into the space. Enter g for get in the command window of ASOperations. Enter 1 for the key and press Enter. You will see the onRead method of the Persister interface invoked in the ASPersistence command window.Enter quit in the command window of the ASPersistence example to shut down the application. The onClose method of the Persister interface is invoked when ASPersistence is stopped.You can use the ASPersistence example with a database for the data store. The default database supported in the code is PostgreSQL. The class MySQLConnection is also provided to show you how easy it is to build on the current ASPersistence example to support a different database.Complete these steps to use the ASPersistence example with a database:
2. Create a database for use with the ASPersistence example.
3. Modify your CLASSPATH to include the JDBC driver jar file for your database
4. Modify the file ASPersistence.java as follows:
c. Comment out the following lines in the ASPersistence constructor:
5. Modify the file ASPersister.java as follows:
a. Ensure that the values for DB_NAME, DB_HOST, USER_NAME, and USER_PASS are set appropriately for your database.
b.
c. In the onOpen method, ensure that the appropriate database connection class is being instantiated.
6. Rebuild Examples.jar.
7. Invoke the ASPersistence and ASOperations examples as described in Starting ASPersistence, and ensure that your CLASSPATH has been set appropriately as described in Step 3.
![]() |
Copyright © TIBCO Software Inc. All Rights Reserved |