Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8313945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:39:40+00:00 2026-06-08T20:39:40+00:00

In a simple RMI program I managed to pass Context between two Threads. Now

  • 0

In a simple RMI program I managed to pass Context between two Threads. Now I need to move setting/reporting from Context to AspectJ class.

My problem is: How to move Context if I need to use it as an argument in greeting(Context)

HelloIF

public interface HelloIF extends Remote {
    String greeting(Context c) throws RemoteException;
}

Hello

public class Hello extends UnicastRemoteObject implements HelloIF {

    public Hello() throws RemoteException {
    }

    public String greeting(Context c) throws RemoteException {
        c.report();
        return "greeting";
    }
}

RMIServer

public class RMIServer {

    public static void main(String[] args) throws RemoteException, MalformedURLException {
        LocateRegistry.createRegistry(1099);
        HelloIF hello = new Hello();
        Naming.rebind("server.Hello", hello);
        System.out.println("server.RMI Server is ready.");
    }
}

RMIClient

public class RMIClient {
    public static void main(String[] args) throws RemoteException, MalformedURLException, NotBoundException {

        Context context = new Context("request1", Thread.currentThread().getName()+System.currentTimeMillis());

        Registry registry = LocateRegistry.getRegistry("localhost");
        HelloIF hello = (HelloIF) registry.lookup("server.Hello");
        System.out.println(hello.greeting(context));

        context.report();

    }
}

Context

public class Context implements Serializable
{
    private String requestType;
    private String distributedThreadName;

    public Context(String requestType, String distributedThreadName)
    {
        this.requestType = requestType;
        this.distributedThreadName = distributedThreadName;
    }

    (...)

    public void report() {
        System.out.println("thread : "
                + Thread.currentThread().getName() + " "
                + Thread.currentThread().getId());

        System.out.println("context : "
                + this.getDistributedThreadName() + " " + this.getRequestType());
    }
}

and finally an empty AspectJ class

@Aspect
public class ReportingAspect {
    @Before("call(void main(..))")
    public void beforeReportClient(JoinPoint joinPoint) throws Throwable {
    }

    @After("call(void main(..))")
    public void afterReportClient(JoinPoint joinPoint) throws Throwable {
    }

    @Before("call(String greeting(..))")
    public void beforeReportGreeting(JoinPoint joinPoint) throws Throwable {
    }

    @After("call(String greeting(..))")
    public void afterReportGreeting(JoinPoint joinPoint) throws Throwable {
    }

}

How can I move from Hello and RMIClient Context() constructor and c/context.report()s to ReportingAspect?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:39:42+00:00Added an answer on June 8, 2026 at 8:39 pm

    You can pass the arguments to a function, and the underlying object, to Advice, thus:

    @Before("execution(* greeting(..)) && target(target) && " +
            "args(context)")
    public void beforeReportGreeting(HelloIF target, Context context) {
           context.doSomething();
           target.doSomething();
    }
    

    Study the AspectJ annotation documentation for the full details. It can be done for all the advice types.

    Edit Reading the question in more details, it sounds as if you want to make the Context object something constructed and controlled by the aspect, while still passing it as an argument to Hello.greeting().

    That’s not something that makes sense. Your underlying system ought to work OK without any AOP going on. So if the Context object is part of that underlying domain, then it’s not a good idea for the Aspect to be in charge of its construction and management.

    If the Context is only relevant to the Aspect, then you would remove all reference to the context from the domain classes (so greeting() would take no parameters) and build the Context object(s) in the Aspect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do a simple program for RMI. But, I'm getting the following
Within my program I'm using two RMI servers, which provide different methods, to simulate
As I understand it, once I've set up an RMI communications link between two
Right now I'm getting this exception from a simple JMS client I wrote to
I managed to write simple program which should simulate passing control in system consisting
This is happening on a network application using JGroups library and a simple RMI
Simple thing I'm doing is connecting to retrieving user's name from Facebook and passing
Simple enough situation. I've got a MongoDB database with a bunch of information from
I was wondering what the simplest program for sending an object from my Android
In a simple RMI game I'm writing (an assignment in uni), I reveice: java.rmi.MarshalException:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.