Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] Plz help in AspectJ RMI code....to Remove Error

Just a guess, but you may be running rmic over non-woven classes.  So, the stub and skeleton classes that are generated are not affected by the declare parents in your aspect.  Make sure that you run rmic against classes that are already woven by aspectj.

If this does not help, then you will need to provide some more information on how you are compiling and running your code.

On Sun, Mar 21, 2010 at 9:51 AM, inderjit singh <inderp10@xxxxxxxxxxx> wrote:


Inderjit Singh Dhanoa
(Sr.Lecturer)
BIS College of Engineering & Tech.,Moga
Cell No.98556-55244

--- On Sun, 21/3/10, inderjit singh <inderp10@xxxxxxxxxxx> wrote:

From: inderjit singh <inderp10@xxxxxxxxxxx>
Subject: Plz help in AspectJ RMI code....to Remove Error
To: aspectj-dev@xxxxxxxxxxx
Date: Sunday, 21 March, 2010, 9:54 PM

With respect to all..........

Sir,

I am developing AspectJ RMI Auction System in Eclipse Environment..........
I have developed the following components.......

Server side:
AuctionInterface.java
Auctioneer.java
ServerAspect.aj
Notifiable.java

and Client Side
AuctionInterface.java
Auction.java
Notifiable.java

Coding is given as follows:
AuctionInterface.java:
package client1;

import java.rmi.Remote;
import java.rmi.RemoteException;


public interface AuctionInterface extends Remote {
    public void setCurrentBid(String bid) throws RemoteException;
    public String getCurrentBid() throws RemoteException;
    public String getMinBid() throws RemoteException;
    public String getProduct() throws RemoteException;

    // called by clients to register for server callbacks
    public void registerForNotification(Notifiable n) throws RemoteException;
}

Notifiable.java

ackage source;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Notifiable extends Remote {
     public void notify(Integer reason) throws RemoteException;
}


Auctioneer.java
package server;

import java.rmi.RemoteException;
import java.rmi.*;
import java.util.*;

public class Auctioneer implements AuctionInterface {

     private String minBid;
        private String currentBid;
        private String product;

        private Vector clientList = null;
       
        public Auctioneer(String product, String minBid)
                    throws RemoteException
        {
           super();
          
        setProduct(product);
           setMinBid(minBid);
           clientList = new Vector();
        }

        public String getCurrentBid() throws RemoteException {
            return currentBid;
        }

        public String getMinBid() throws RemoteException {
            return minBid;
        }

        public String getProduct() throws RemoteException {
            return product;
        }

        public void setCurrentBid(String b) throws RemoteException {
            currentBid = b;
            for(Enumeration clients = clientList.elements();
                clients.hasMoreElements();) {
                    Notifiable thingToNotify = (Notifiable) clients.nextElement();
                    thingToNotify.notify(new Integer(0));
                }
        }

        public void setMinBid(String m) {
            minBid = m;
        }

        public void setProduct (String p) {
            product = p;
        }

        public void registerForNotification(Notifiable n) throws RemoteException {
            clientList.addElement(n);
        }
    public static void main(String[] args) {
        if(args.length == 0) {
            System.out.println("USAGE: java <product name> <min bid>");
            System.exit(0);
        }
        System.setSecurityManager(new RMISecurityManager());
        try {
               Auctioneer thisOne = new Auctioneer(args[0], args[1]);
        
        System.out.println("Distribution Service has Successfully bound");
            }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

}

ServerAspect.aj
package server;

import java.rmi.*;

import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;


public aspect ServerAspect {
    public String name;
    declare parents:Auctioneer implements AuctionInterface;
    declare parents: AuctionInterface extends java.rmi.Remote;
    pointcut AuctionInit(Auctioneer a,String pr,String mb):execution(Auctioneer.new(..) throws RemoteException) && this(a) && args(pr,mb);

        after(Auctioneer a,String pr,String mb) throws RemoteException:AuctionInit(a,pr,mb)
        {
     try {
       
        UnicastRemoteObject.exportObject(a);
        name = "//localhost/"+pr;
        Naming.rebind(name,a);
        System.out.println(a);
        System.out.println(pr);
        System.out.println(mb);
       
        } catch (java.net.MalformedURLException me)
           {
            System.out.println(me.toString());
        }
        }
   
}

Auction.java(Client Side):
package client1;

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;


import java.awt.*;
import java.rmi.*;
import java.rmi.Naming;
import java.rmi.server.*;

import client1.AuctionInterface;
public class Auction extends Frame implements Notifiable, ActionListener {

     TextField bid = null;
        Label currentBidLabel, productLabel;
        Button btnSubmit, btnClear, btnClose;

        private String currentBid = "    ";
        private String product = "";
       
        AuctionInterface auctioneer;

        public Auction() {
           super("Auction Program");

          //auctioneer = new Auctioneer(product, currentBid);

           Panel p1 = new Panel();
           p1.add(btnSubmit = new Button("Submit bid"));
           p1.add(btnClear = new Button("Clear"));
           p1.add(btnClose = new Button("Close"));

           add(p1, "South");

           add(productLabel = new Label(product), "North");

           Panel p2 = new Panel();
           p2.setLayout(new GridLayout(3,0));

           Panel p3 = new Panel();
           p3.add(new Label("current bid: "));
           currentBidLabel = new Label(currentBid);
           p3.add(currentBidLabel);
           p2.add(p3);
           bid = new TextField();
           p2.add(new Label("Your bid."));
           p2.add(bid);
           add(p2, "Center");

           btnSubmit.addActionListener(this);
           btnClear.addActionListener(this);
           btnClose.addActionListener(this);


            try {
                UnicastRemoteObject.exportObject(this);
                }
            catch(RemoteException re) {
                re.printStackTrace();
            }

           setBounds(50, 50, 300, 200);
           setVisible(true);
       }

        public void actionPerformed(ActionEvent ae) {
            if(ae.getActionCommand().equals("Close")) {
                dispose();
                System.exit(0);
            }
            if(ae.getActionCommand().equals("Submit bid")) {
                if(bid.getText().equals("")) {
                    bid.setText("Enter a number");
                } else { // should also check invalid syntax and bids too low
                    try {
                        auctioneer.setCurrentBid(bid.getText());
                        //currentBid = auctioneer.getCurrentBid();
                    }
                    catch(RemoteException re) {
                        re.printStackTrace();
                    }
                    //currentBidLabel.setText(currentBid);
                }
            }
            if(ae.getActionCommand().equals("Clear")) {
            }
        }

        public void notify(Integer reason) {
            if(reason.intValue() == 0) {
                try {
                    currentBid = auctioneer.getCurrentBid();
                    currentBidLabel.setText(currentBid);
                }
                catch (RemoteException re) {
                    re.printStackTrace();
                }
            }
        }

       public static void main(String [] args) {
           if(args.length == 0) {
               System.out.println("USAGE: java Auction <remote host> <product name>");
               System.exit(0);
           }
           System.out.println(args[0]);
           System.setSecurityManager(new RMISecurityManager());
           //String serverName = "//" + args[0] + "/" + args[1];
           String serverName = "rmi://localhost/" + args[0];
           Auction auc = new Auction();
           auc.productLabel.setText(args[0]);
           try {
               System.out.println(serverName);
               //auc.auctioneer=(AuctionInterface)auc.auctioneer;
 (118)          auc.auctioneer = (AuctionInterface) Naming.lookup(serverName);
             
               auc.auctioneer.registerForNotification(auc);
               auc.bid.setText(auc.auctioneer.getMinBid());
            }
            catch (ClassCastException nbe) {
                auc.bid.setText(args[0] + " is not available");
                nbe.printStackTrace();
            }
            catch(Exception e) {
                e.printStackTrace();
            }


       }

}

But I am getting Following error on Client Side.......
rmi://localhost/Creeam
java.lang.ClassCastException: server.Auctioneer_Stub
    at client1.Auction.main(Auction.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at net.genady.rmi.logger.Runner.main(Runner.java:137)

i have highlighted Red line above where this error occurs above........

Plz help me to remove this error.............
I m using RMI Plug in and AJDT Plug in........... for this

Reply soon thanks
I am waiting......................................

Inderjit Singh Dhanoa
(Sr.Lecturer)
BIS College of Engineering & Tech.,Moga
Cell No.98556-55244


Your Mail works best with the New Yahoo Optimized IE8. Get it NOW!.


The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.

_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



Back to the top