Game updates improvements
* Added a set of tables which define game updates and their targets. These definitions replace the old enumerate type. Added a set of triggers which automatically create specific update tables, insert missing entries, etc... when game update types are being manipulated. * Removed manual insertion of game updates from empire creation function and universe generator. * Added registration of core update targets (i.e. planets and empires), updated all existing game update processing functions and added type registrations * Created Maven project for game updates control components, moved existing components from the -simple project, rewritten most of what they contained, added new components for server-side update batch processing
This commit is contained in:
parent
ba6a1e2b41
commit
56eddcc4f0
93 changed files with 4004 additions and 578 deletions
legacyworlds-server-beans-simple/src/main
java/com/deepclone/lw/beans/updates
resources/configuration
|
@ -1,138 +0,0 @@
|
|||
package com.deepclone.lw.beans.updates;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import com.deepclone.lw.cmd.admin.logs.LogLevel;
|
||||
import com.deepclone.lw.interfaces.eventlog.Logger;
|
||||
import com.deepclone.lw.interfaces.eventlog.SystemLogger;
|
||||
import com.deepclone.lw.interfaces.game.UpdatesDAO;
|
||||
import com.deepclone.lw.interfaces.sys.MaintenanceStatusException;
|
||||
import com.deepclone.lw.interfaces.sys.SystemStatus;
|
||||
import com.deepclone.lw.interfaces.sys.TickStatusException;
|
||||
import com.deepclone.lw.interfaces.sys.Ticker;
|
||||
import com.deepclone.lw.interfaces.sys.Ticker.Frequency;
|
||||
|
||||
|
||||
|
||||
public class GameUpdateBean
|
||||
implements InitializingBean , Runnable
|
||||
{
|
||||
private Ticker ticker;
|
||||
private SystemStatus systemStatus;
|
||||
private SystemLogger logger;
|
||||
|
||||
private TransactionTemplate tTemplate;
|
||||
private UpdatesDAO updatesDao;
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setTicker( Ticker ticker )
|
||||
{
|
||||
this.ticker = ticker;
|
||||
}
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setSystemStatus( SystemStatus systemStatus )
|
||||
{
|
||||
this.systemStatus = systemStatus;
|
||||
}
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setLogger( Logger logger )
|
||||
{
|
||||
this.logger = logger.getSystemLogger( "GameUpdate" );
|
||||
}
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setTransactionManager( PlatformTransactionManager transactionManager )
|
||||
{
|
||||
this.tTemplate = new TransactionTemplate( transactionManager );
|
||||
}
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setUpdatesDAO( UpdatesDAO updatesDao )
|
||||
{
|
||||
this.updatesDao = updatesDao;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet( )
|
||||
{
|
||||
try {
|
||||
this.endPreviousTick( );
|
||||
} catch ( MaintenanceStatusException e ) {
|
||||
// Do nothing
|
||||
}
|
||||
this.ticker.registerTask( Frequency.MINUTE , "Game update" , this );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run( )
|
||||
{
|
||||
// Attempt to end the previous tick, if e.g. maintenance mode was initiated while it was
|
||||
// being processed
|
||||
try {
|
||||
this.endPreviousTick( );
|
||||
} catch ( MaintenanceStatusException e1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Initiate next tick
|
||||
long tickId;
|
||||
try {
|
||||
tickId = this.systemStatus.startTick( );
|
||||
} catch ( TickStatusException e ) {
|
||||
throw new RuntimeException( "tick initiated while previous tick still being processed" , e );
|
||||
} catch ( MaintenanceStatusException e ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Execute tick
|
||||
this.logger.log( LogLevel.DEBUG , "Tick " + tickId + " started" ).flush( );
|
||||
this.executeTick( tickId );
|
||||
}
|
||||
|
||||
|
||||
private void endPreviousTick( )
|
||||
throws MaintenanceStatusException
|
||||
{
|
||||
Long currentTick = this.systemStatus.checkStuckTick( );
|
||||
if ( currentTick == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.logger.log( LogLevel.WARNING , "Tick " + currentTick + " restarted" ).flush( );
|
||||
this.executeTick( currentTick.longValue( ) );
|
||||
}
|
||||
|
||||
|
||||
private void executeTick( final long tickId )
|
||||
{
|
||||
boolean hasMore;
|
||||
do {
|
||||
hasMore = this.tTemplate.execute( new TransactionCallback< Boolean >( ) {
|
||||
|
||||
@Override
|
||||
public Boolean doInTransaction( TransactionStatus status )
|
||||
{
|
||||
return updatesDao.processUpdates( tickId );
|
||||
}
|
||||
|
||||
} );
|
||||
} while ( hasMore );
|
||||
this.logger.log( LogLevel.TRACE , "Tick " + tickId + " completed" ).flush( );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package com.deepclone.lw.beans.updates;
|
||||
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.SqlOutParameter;
|
||||
import org.springframework.jdbc.core.SqlParameter;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcCall;
|
||||
|
||||
import com.deepclone.lw.interfaces.game.UpdatesDAO;
|
||||
|
||||
|
||||
|
||||
public class UpdatesDAOBean
|
||||
implements UpdatesDAO
|
||||
{
|
||||
|
||||
private SimpleJdbcCall process;
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.process = new SimpleJdbcCall( dataSource );
|
||||
this.process.withCatalogName( "sys" ).withFunctionName( "process_updates" );
|
||||
this.process.withoutProcedureColumnMetaDataAccess( );
|
||||
this.process.addDeclaredParameter( new SqlParameter( "tick_id" , Types.BIGINT ) );
|
||||
this.process.addDeclaredParameter( new SqlOutParameter( "has_more" , Types.BOOLEAN ) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean processUpdates( long tickId )
|
||||
{
|
||||
Map< String , Object > m = this.process.execute( tickId );
|
||||
return (Boolean) m.get( "has_more" );
|
||||
}
|
||||
|
||||
}
|
|
@ -10,13 +10,11 @@
|
|||
<import resource="simple/empire-management-bean.xml" />
|
||||
<import resource="simple/fleet-management-bean.xml" />
|
||||
<import resource="simple/fleets-dao-bean.xml" />
|
||||
<import resource="simple/game-update-bean.xml" />
|
||||
<import resource="simple/map-viewer-bean.xml" />
|
||||
<import resource="simple/message-beans.xml" />
|
||||
<import resource="simple/planet-dao-bean.xml" />
|
||||
<import resource="simple/planets-management-bean.xml" />
|
||||
<import resource="simple/universe-dao-bean.xml" />
|
||||
<import resource="simple/universe-generator-bean.xml" />
|
||||
<import resource="simple/updates-dao-bean.xml" />
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
|
||||
<!-- Game update bean -->
|
||||
<bean id="gameUpdate" class="com.deepclone.lw.beans.updates.GameUpdateBean" />
|
||||
|
||||
</beans>
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
|
||||
<bean id="updatesDAO" class="com.deepclone.lw.beans.updates.UpdatesDAOBean" />
|
||||
|
||||
</beans>
|
Reference in a new issue