📄 serverserviceimpl.java
字号:
login( args );
}
else
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
int indexRole = methodName.indexOf( "/" );
String role = RemoteStorage.ROLE;
if ( indexRole > 0 )
{
role = methodName.substring( 0, indexRole );
methodName = methodName.substring( indexRole + 1 );
}
try
{
RemoteService service = (RemoteService) ( (RemoteSessionImpl) session ).lookupService( role );
service.remoteMethodCall( methodName, args, out );
}
catch ( RaplaException ex )
{
getLogger().error( ex.getMessage(), ex );
throw ex;
}
out.close();
return out.toByteArray();
}
return new byte[] {};
}
public StorageOperator getOperator()
{
return operator;
}
static UpdateEvent createTransactionSafeUpdateEvent( UpdateResult updateResult )
{
User user = updateResult.getUser();
UpdateEvent saveEvent = new UpdateEvent();
if ( user != null )
{
saveEvent.setUserId( ( (RefEntity) updateResult.getUser() ).getId() );
}
Iterator it = updateResult.getOperations( UpdateResult.Add.class );
while ( it.hasNext() )
{
saveEvent.putStore( (RefEntity) ( (UpdateResult.Add) it.next() ).getNew() );
}
it = updateResult.getOperations( UpdateResult.Change.class );
while ( it.hasNext() )
{
saveEvent.putStore( (RefEntity) ( (UpdateResult.Change) it.next() ).getNew() );
}
it = updateResult.getOperations( UpdateResult.Remove.class );
while ( it.hasNext() )
{
saveEvent.putRemove( (RefEntity) ( (UpdateResult.Remove) it.next() ).getCurrent() );
}
return saveEvent;
}
// Implementation of StorageUpdateListener
synchronized public void objectsUpdated( UpdateResult evt )
{
// notify the client for changes
repositoryVersion++;
UpdateEvent safeResultEvent = createTransactionSafeUpdateEvent( evt );
if ( getLogger().isDebugEnabled() )
getLogger().debug( "Storage was modified. Calling notify." );
for ( Iterator it = safeResultEvent.getStoreObjects().iterator(); it.hasNext(); )
{
RaplaObject obj = (RaplaObject) it.next();
updateMap.remove( obj );
updateMap.put( obj, new Long( repositoryVersion ) );
}
for ( Iterator it = safeResultEvent.getRemoveObjects().iterator(); it.hasNext(); )
{
RaplaObject obj = (RaplaObject) it.next();
updateMap.remove( obj );
removeMap.remove( obj );
removeMap.put( obj, new Long( repositoryVersion ) );
}
}
/** regulary removes all old update messages that are older the updateInterval ( factor 10) and at least 1 hour old */
private final void initEventCleanup()
{
TimerTask cleanupTask = new TimerTask()
{
public void run()
{
initEventCleanup();
}
};
synchronized ( operator.getLock() )
{
Timer timer = new Timer( true ); // Start timer as daemon-thread
int delay = 10000;
for ( Iterator it = updateMap.keySet().iterator(); it.hasNext(); )
{
RefEntity key = (RefEntity) it.next();
Long lastVersion = (Long) updateMap.get( key );
if ( lastVersion.longValue() <= cleanupPointVersion )
{
updateMap.remove( key );
}
}
for ( Iterator it = removeMap.keySet().iterator(); it.hasNext(); )
{
RefEntity key = (RefEntity) it.next();
Long lastVersion = (Long) removeMap.get( key );
if ( lastVersion.longValue() <= cleanupPointVersion )
{
removeMap.remove( key );
}
}
cleanupPointVersion = repositoryVersion;
if ( operator.isConnected() )
{
try
{
delay = operator.getPreferences( null ).getEntryAsInteger( UpdateModule.REFRESH_INTERVAL_ENTRY,
delay );
}
catch ( RaplaException e )
{
getLogger().error( "Error during cleanup.", e );
}
}
timer.schedule( cleanupTask, Math.max( DateTools.MILLISECONDS_PER_HOUR, delay * 10 ) );
}
}
synchronized String createUpdateXML( long clientRepositoryVersion ) throws RaplaException, IOException
{
long currentVersion = this.repositoryVersion;
if ( clientRepositoryVersion < currentVersion )
{
UpdateEvent safeResultEvent = new UpdateEvent();
safeResultEvent.setRepositoryVersion( currentVersion );
for ( Iterator it = updateMap.keySet().iterator(); it.hasNext(); )
{
RefEntity key = (RefEntity) it.next();
Long lastVersion = (Long) updateMap.get( key );
if ( lastVersion.longValue() > clientRepositoryVersion )
{
safeResultEvent.putStore( key );
}
}
for ( Iterator it = removeMap.keySet().iterator(); it.hasNext(); )
{
RefEntity key = (RefEntity) it.next();
Long lastVersion = (Long) removeMap.get( key );
if ( lastVersion.longValue() > clientRepositoryVersion )
{
safeResultEvent.putRemove( key );
}
}
String xml = RemoteStorageImpl.createUpdateEvent( getContext(), operator.getCache(), safeResultEvent );
return xml;
}
// Empty String if nothing is expected
return "<uptodate/>";
}
public void updateError( RaplaException ex )
{
if ( getLogger() != null )
getLogger().error( ex.getMessage(), ex );
try
{
stop();
// messagingServer.disconnect();
}
catch ( Exception e )
{
if ( getLogger() != null )
getLogger().error( e.getMessage() );
}
}
public void storageDisconnected()
{
try
{
stop();
}
catch ( Exception e )
{
if ( getLogger() != null )
getLogger().error( e.getMessage() );
}
}
public void checkServerVersion( String clientVersion ) throws RaplaException
{
String serverVersion = i18n.getString( "rapla.version" );
if ( !serverVersion.equals( clientVersion ) )
{
throw new RaplaException( "Incompatible client/server versions. Please change your client to version "
+ serverVersion
+ ". If you are using java-webstart a simple reload and restart could do that!" );
}
}
public void login( String username, String password ) throws RaplaException
{
this.getLogger().debug( "User '" + username + "' is requesting login " );
authenticate( username, password );
if ( authenticationStore != null)
{
User user = this.operator.getUser( username );
if ( user == null )
{
user = new UserImpl();
( (RefEntity) user ).setId( this.operator.createIdentifier( User.TYPE ) );
}
else
{
user = (User) this.operator.editObject( user, null );
}
if ( authenticationStore.initUser( user, username, password,
this.operator.getSuperCategory()
.getCategory( Permission.GROUP_CATEGORY_KEY ) ) )
{
this.operator.storeAndRemove( new Entity[]
{ user }, Entity.ENTITY_ARRAY, user );
}
}
}
public void authenticate( String username, String password ) throws RaplaException
{
synchronized ( this.operator.getLock() )
{
if ( authenticationStore != null && authenticationStore.authenticate( username, password ) )
{
// do nothing
}
else
{
this.operator.authenticate( username, password );
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -