If an application requires a callback (for example, to allow the client framework to provide notification of synchronization results) create a custom callback handler.
import com.sybase.persistence.DefaultCallbackHandler;
……
public class Test
{
public static void main(String[] args)
{
SMP101DB.registerCallbackHandler(new MyCallbackHandler());
GenericList<SynchronizationGroup> sgs = new GenericList<SynchronizationGroup>();
sgs.add(SMP101DB.getSynchronizationGroup("sg1"));
sgs.add(SMP101DB.getSynchronizationGroup("sg2"));
SMP101DB.beginSynchronize(sgs, "my test synchronization context");
}
}
class MyCallbackHandler extends DefaultCallbackHandler
{
//The onSynchronize method overrides the
//onSynchronize method from DefaultCallbackHandler.
public int onSynchronize(GenericList<SynchronizationGroup> groups, SynchronizationContext context)
{
if ( context == null )
{
return SynchronizationAction.CANCEL;
}
if (!("my test synchronization context".equals((String)(context.getUserContext()))))
{
return super.onSynchronize(groups, context);
}
switch (context.getStatus())
// The application is waiting for input from the user.
// This section demonstrates that you can stop the synchronization or
// let it proceed depending on the status of the application.
{
case SynchronizationStatus.STARTING:
if (waitForMoreChanges())
{
return SynchronizationAction.CANCEL;
}
else
{
return SynchronizationAction.CONTINUE;
}
default:
return SynchronizationAction.CONTINUE;
}
}
}