Как объявить значение переменной во время работы java RMI server?
Hi, I am new in Java RMI and trying to do some learning in different condition. I don't know what I am trying to do is appropriate or not. I am trying to set a variable value during starting the server which is accessible to client. Let me explain what I have tried so far and what I am trying to do.
Что я уже пробовал:
So far I have developed an RMI application where client gives an input & get the factorial for that. I have 4 class for the application. Those along with code are following.
Класс сервера - FacServer
import java.rmi.*; public class FacServer.java { public static void main(String a[]) throws Exception { FacImpl obj = new FacImpl(); Naming.rebind("FAC",obj); System.out.println("Server started"); } }
Класс Клиента - FacClient.java
import java.util.*; import java.io.*; import java.rmi.*; public class FacClient { public static void main(String a[]) throws Exception { FacInt obj = (FacInt)Naming.lookup("FAC"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter a number: "); String s = null; try { s = br.readLine(); } catch(IOException ioe) { System.err.println(ioe.getMessage()); } int r = Integer.parseInt(s); int n= obj.fac(r); System.out.println("Factorial is "+n); } }
Класс Реализации - FacImpl.java
<pre>import java.rmi.server.*; public class FacImpl extends UnicastRemoteObject implements FacInt { public FacImpl() throws Exception { super(); } public int fac(int x) { int i,j=1; for(i=x;i>1;i--) j=j*i; return j; } }
Класс Интерфейса - FacInt.java
import java.rmi.Remote; public interface FacInt extends Remote { public int fac(int x) throws Exception; }
It works fine. Now I want to set some limitation in server side. For example server won't calculate the factorial value for more than 5. I know I can do it in implementation class easily. But I want to declare it when I start the server. For example to set limitation 5 I should start the server in following way. java FacServer 5 So if client input a value more than 5 it will get an error reply. Is it possible to do so? Also can I show the factorial value in server side also if client provide an accepted value?