guyue0505

Greenhorn
+ Follow
since May 25, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by guyue0505

Hello, I have a question about synchronized like these:
1) I have a class named LockManager whitch do "genCookie", "LockRecord" ,
"unlockRecord" ...
synchronized boolean unlockRecNo(
long recNo , long lockCookie ){
....
}
synchronized boolean lockRecNo(
long recNo , long lockCookie ){
....
}
2) In client, when i Book a seat I do like:
lockManager.LockRecord;
Book;
lockManager.unlock;
Doing like these , is right?
Thank you first.
In my application , i have a class named LockManager which control the lock and unlock . i think i will need a hashMap in this class. The key is the recNo and the value is the lockCookie of the correspond recNo.
And the lockManager has a function named setMap(Map hashMap){ this.hashMap =
hashMap; }
My question is where can i put the hashMap's declaretion , in Server.java
or other place?
in the GUI of my client ,i give three ways of searching:
first : user can searching all records if user dose not input anying .
second : user can searching by only the name .
third : user can searching by only the location .
My question is i does not give the way of searching :
search the record by the name and the location !
Am i right ? Or I must give the way of "name and location "?
only the name
thanks first
my question is how can i put the RemoteData_Stub.class into the
client package?
thanks , now i get rid of the code of
"System.setSecurityManager(new RMISecurityManager());"
but when i run i get new exception like this :
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: suncertify.server.RemoteData_Stub (no
security manager: RMI class loader disabled)
java.lang.ClassNotFoundException: suncertify.server.RemoteData_Stub (no security
manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
at java.io.ObjectInputStream.inputClassDescriptor(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.io.ObjectInputStream.inputObject(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
by the way ,because i put the remote interface named remoteData in the <db> package , and put
the class named remoteDBAccess which implemented
remoteData in the server package.
how can i put the RemoteData_Stub.class into the
client package?
where can i pun the RemoteDBAccessImpl ?
in the suncertify.server.Server or
in the suncertify.server.Db?
(the RemoteDBAccessImpl is the class which implements the remote interface of RemoteDBAccess )
when i run jar in remote
1)java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: suncertify.server.RemoteData_Stub (no
security manager: RMI class loader disabled)
java.lang.ClassNotFoundException: suncertify.server.RemoteData_Stub (no security
manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
at java.io.ObjectInputStream.inputClassDescriptor(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.io.ObjectInputStream.inputObject(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at suncertify.client.Client.setMode(Client.java:65)
at suncertify.client.Client.main(Client.java:89)
But i add the LocateRegistry.createRegistry(1099);
and run " rmic -d . suncertify.server.RemoteData"
2) and i add the code "System.setSecurityManager(new RMISecurityManager())" and run again But
java.security.AccessControlException: access denied (java.net.SocketPermission f
enet-steven resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getByName(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown S
ource)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown S
ource)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
Please help me
when i run client by Remote Mode
i get exception:
java.security.AccessControlException: access denied (java.net.SocketPermission f
enet-steven resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getByName(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown S
ource)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown S
ource)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
I create a jar file like :
1)jar -cvfm client.jar manifest_client.mf suncertify\client\*.class suncertify\db\*.class
2)jar -cvfm server.jar manifest_server.mf suncertify\server\*.class suncertify\db\*.class
manifest_client.mf like:
Manifest-Version: 1.0
Created-By: 1.4.0 (Sun Microsystems Inc.)
Main-Class: suncertify.client.client
manifest_server.mf like:
Manifest-Version: 1.0
Created-By: 1.4.0 (Sun Microsystems Inc.)
Main-Class: suncertify.server.server
So i create client.jar and server.jar Ok;
and last i run like this:
java -jar sever.jar ; But some errors occurs:
Exception in thread "main" java.lang.NoClassDefFoundError: suncertify/server/ser
ver
Then create wrappers or callers for Data.java that handle the remote (RMI or sockets) feature. (My design has a DbServer class that is a Facade that wraps Data.java.)
please give me a example ,I am not unstand
My question is about lcoal and Remote Mode
I think for some days about Design:
1) I create a class Data.java which implemts the DBAccess interface .
public class Data{
public readRecord(long recNo)
throws RecordNotFoundException{
//read record from the .db file
}
.....
}
2) i create a interface RemoteDBAccess.java
import java.rmi.*;
public interface RemoteDBAccess extends Remote{
public String [] readRecord(long recNo)
throws RecordNotFoundException,RemoteException;
....
}
I also create a class RemoteData.java
import java.rmi.*;
import java.rmi.server.*;
/**
*This is the implements from RemoteDBAccess used for Remote mode
*@date 2003-05-18
*@author Steven Gu
*/

public class RemoteData
extends UnicastRemoteObject
implements RemoteDBAccess{

public RemoteData () throws RemoteException{
super();
}
public String [] readRecord(long recNo)
throws
RecorNotFoundException ,
RemoteException{
//some codes :.....
}
}
can you tell me Am i right?
Thank you very much
Yes I also have this question!
Sorry , i think the question is very old, but
I found and look a lot of topics in javaranch.
But i still unstand.
in my document :
Required Interface
Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:
package suncertify.db;
public interface DBAccess
{
// Reads a record from the file. Returns an array where each
// element is a record value.
public String [] readRecord(long recNo)
throws RecordNotFoundException;
// Modifies the fields of a record. The new value for field n
// appears in data[n]. Throws SecurityException
// if the record is locked with a cookie other than lockCookie.
public void updateRecord(long recNo, String[] data, long lockCookie)
throws RecordNotFoundException, SecurityException;
// Deletes a record, making the record number and associated disk
// storage available for reuse.
// Throws SecurityException if the record is locked with a cookie
// other than lockCookie.
public void deleteRecord(long recNo, long lockCookie)
throws RecordNotFoundException, SecurityException;
// Returns an array of record numbers that match the specified
// criteria. Field n in the database file is described by
// criteria[n]. A null value in criteria[n] matches any field
// value. A non-null value in criteria[n] matches any field
// value that begins with criteria[n]. (For example, "Fred"
// matches "Fred" or "Freddy".)
public long[] findByCriteria(String[] criteria);
// Creates a new record in the database (possibly reusing a
// deleted entry). Inserts the given data, and returns the record
// number of the new record.
public long createRecord(String [] data)
throws DuplicateKeyException;
// Locks a record so that it can only be updated or deleted by this client.
// Returned value is a cookie that must be used when the record is unlocked,
// updated, or deleted. If the specified record is already locked by a different
// client, the current thread gives up the CPU and consumes no CPU cycles until
// the record is unlocked.
public long lockRecord(long recNo)
throws RecordNotFoundException;
// Releases the lock on a record. Cookie must be the cookie
// returned when the record was locked; otherwise throws SecurityException.
public void unlock(long recNo, long cookie)
throws SecurityException;
}
i think Sun says the class cannot be modi by myself.
someone say create a top abstract class and
two dbaccess ,one is local and other is a
remote;
can you give me a example? please help me!!!
Sorry , i think the question is very old, but
I found and look a lot of topics in javaranch.
But i still unstand.
in my document :
Required Interface
Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:
package suncertify.db;
public interface DBAccess
{
// Reads a record from the file. Returns an array where each
// element is a record value.
public String [] readRecord(long recNo)
throws RecordNotFoundException;
// Modifies the fields of a record. The new value for field n
// appears in data[n]. Throws SecurityException
// if the record is locked with a cookie other than lockCookie.
public void updateRecord(long recNo, String[] data, long lockCookie)
throws RecordNotFoundException, SecurityException;
// Deletes a record, making the record number and associated disk
// storage available for reuse.
// Throws SecurityException if the record is locked with a cookie
// other than lockCookie.
public void deleteRecord(long recNo, long lockCookie)
throws RecordNotFoundException, SecurityException;
// Returns an array of record numbers that match the specified
// criteria. Field n in the database file is described by
// criteria[n]. A null value in criteria[n] matches any field
// value. A non-null value in criteria[n] matches any field
// value that begins with criteria[n]. (For example, "Fred"
// matches "Fred" or "Freddy".)
public long[] findByCriteria(String[] criteria);
// Creates a new record in the database (possibly reusing a
// deleted entry). Inserts the given data, and returns the record
// number of the new record.
public long createRecord(String [] data)
throws DuplicateKeyException;
// Locks a record so that it can only be updated or deleted by this client.
// Returned value is a cookie that must be used when the record is unlocked,
// updated, or deleted. If the specified record is already locked by a different
// client, the current thread gives up the CPU and consumes no CPU cycles until
// the record is unlocked.
public long lockRecord(long recNo)
throws RecordNotFoundException;
// Releases the lock on a record. Cookie must be the cookie
// returned when the record was locked; otherwise throws SecurityException.
public void unlock(long recNo, long cookie)
throws SecurityException;
}
i think Sun says the class cannot be modi by myself.
someone say create a top abstract class and
two dbaccess ,one is local and other is a
remote;
can you give me a example? please help me!!!