Raising Notifications from RMI

Raising Notifications from RMI

Ever wish you could have your RMI application notify you when it’s using the distributed garbage collector? Sometimes it’s useful to know when a RMI server “kills” an object. Just perform the following steps:

  1. Implement the java.rmi.server.Unreferenced interface in your RMI server.
  2. Provide an implementation for the unreferenced() method.
  3. Specify a value for the java.rmi.dgc.leaveValue system property. This value represents miliseconds (default ten minutes) and it is used to tell how much time must pass without clients interaction before an object is collected.
  4. The client’s interaction represents a “lease contract” that must be updated.

What follows is an example of an RMI server that returns the timestamp of a collected object:

import java.rmi.*;import java.rmi.server.*;import java.util.Properties;public class SumImpl extends UnicastRemoteObject implements SumInterface,Unreferenced{   public SumaImpl()throws RemoteException   {      //optional      super();   }   //the SumInterface method   public int Sum(int a,int b)throws RemoteException{      return (a+b);     }   //the unreferenced method   public void unreferenced()   {      java.util.Date date=new java.util.Date();      System.out.println("Unreferenced called..."+date);   }   //the finalize method   public void finalize()throws Throwable   {      super.finalize();      java.util.Date date=new java.util.Date();      System.out.println("Finalize called..."+date);   }   public static void main(String[] args)   {                    SumImpl SI=null;      //create the remote object      try{         SI=new SumImpl();             }catch(java.rmi.RemoteException e)         {System.out.println(e.getMessage());}      	      try{                 Naming.bind("rmi://localhost:1099/SUMObject",SI);      }catch(java.rmi.AlreadyBoundException e)         {System.out.println(e.getMessage());      }catch(java.net.MalformedURLException e)         {System.out.println(e.getMessage());      }catch(java.rmi.RemoteException e)         {System.out.println(e.getMessage());}               }}

The SumInterface is a simple interface that contains a single method, called Sum. Write this interface and a clasic RMI client, and run the RMI server like this:

<HOME>java ?Djava.rmi.dgc.leaveValue=1000 SumImpl
Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as