Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] Offline Branching(How do it work and how do i should use it)
[CDO] Offline Branching [message #959410] Fri, 26 October 2012 13:48 Go to next message
Michele Preti is currently offline Michele Preti
Messages: 14
Registered: October 2012
Junior Member
Hi,
first I'm sorry for not replying for so long at the post http://www.eclipse.org/forums/index.php/mv/msg/408206/953303/#msg_953303 where I was supposed to try range-based mapping strategies, but knowing it can be done i'll first focus on another aspect, then go back and try to fine tune.

from org.eclipse.emf.cdo.internal.server.syncing.OfflineClone :
@Override
  public InternalCommitContext createCommitContext(InternalTransaction transaction)
  {
    CDOBranch branch = transaction.getBranch();
    if (branch.isLocal())
    {
      return createNormalCommitContext(transaction);
    }

    if (getState() != ONLINE)
    {
      return createBranchingCommitContext(transaction, branch);
    }

    return createWriteThroughCommitContext(transaction);
  }


so, when the clone is offline, and a transaction try to commit, it will create a new offline (or local) branch, make the transaction point at it, and commit.
If i open a new transaction (or restart the clone), this will point to the MAIN branch, and if i'm offline and commit, i'll gett a new offline branch. This mean that, as soon as the main server is reachable and the clone is online, i'll have to merge 2 branches. right? That's not really a problem, just need to know if i get it right.

The OfflineExampleClone did not automatically merge the offline branch when it go online, and i add this myself:
            CDONet4jSession session = configuration.openNet4jSession();
	    CDORepositoryInfo repositoryInfo = session.getRepositoryInfo();
	    System.out.println("Connected to " + repositoryInfo.getName());

	    transaction = session.openTransaction();
	    createSessionListener
            session.addListener(new IListener()
	    {
	      private boolean justStarted = true;
	      private boolean wasOffline;

	      public void notifyEvent(IEvent event)
	      {
	        if (event instanceof CDOCommonRepository.StateChangedEvent)
	        {
	          CDOCommonRepository.StateChangedEvent e = (CDOCommonRepository.StateChangedEvent)event;
	          State newState = e.getNewState();
	          System.out.println("State changed to " + newState);
	          if (autoMerging)
	          {
	            merge(session, newState);
	          }
	        }
	      }



The real problem is that after the first commit, and the creation of the first offline branch, if i reload my clone or simply open a new tranasction that will point to the MAIN and i can't see the previous modifications (that are in the offline branch). I surelly (well, more or less, see next point) can check if an offline branch is still open and switch to that, so until the clone stay offline i'll always work in a unique offline branch. But this is not really intuitive... the offline cdlone should act transparently as in Online state, where i can work as i were talking directly with the master. Is not it? (so, this is a "have i get it right?" and if i get it : "it can be improved")

The previous was just a improvable thing. My problem is:

If i do the follow:

1- start the clone in online mode (let it sync)
2- stop the master, the clone is now in offline mode
3- update some items and commit, offline branch created
4- start the master, the clone go online and merge the offline branch
5- stop the master, the clone go offline
6- update some more items, commit, another offline branch created
7- start the master, clone online, merge ???

what offline branches should i merge? If i don't miss it a branch can't be closed, and i can't tell which is the Offline branches i have to merge to persist the last clone Offline-session.

A way to solve this:
- a way to delete a branch, an offline branch after merged is useless...
- a way to close a branch, or at least tell if it has been modified since the last merge or creation.

I hope I made ​​it clear, how can i solve this?

Re: [CDO] Offline Branching [message #960228 is a reply to message #959410] Sat, 27 October 2012 05:36 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5446
Registered: July 2009
Senior Member
Hi Michele,

Instead of listening for CDOCommonRepository.StateChangedEvents from the session you should rather listen for
CDOViewTargetChangedEvents from your transaction(s). There you can detect branch changes no matter why/how they occured
and save the branch name, path or ID to a local file. This file can be loaded by the application at startup time and
influence the opening of the new transaction(s). This way you always start in the same branch that was active when you
exited last.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper



Am 26.10.2012 19:48, schrieb Michele Preti:
> Hi,
> first I'm sorry for not replying for so long at the post
> http://www.eclipse.org/forums/index.php/mv/msg/408206/953303/#msg_953303 where I was supposed to try range-based
> mapping strategies, but knowing it can be done i'll first focus on another aspect, then go back and try to fine tune.
>
> from org.eclipse.emf.cdo.internal.server.syncing.OfflineClone :
>
> @Override
> public InternalCommitContext createCommitContext(InternalTransaction transaction)
> {
> CDOBranch branch = transaction.getBranch();
> if (branch.isLocal())
> {
> return createNormalCommitContext(transaction);
> }
>
> if (getState() != ONLINE)
> {
> return createBranchingCommitContext(transaction, branch);
> }
>
> return createWriteThroughCommitContext(transaction);
> }
>
>
> so, when the clone is offline, and a transaction try to commit, it will create a new offline (or local) branch, make
> the transaction point at it, and commit.
> If i open a new transaction (or restart the clone), this will point to the MAIN branch, and if i'm offline and commit,
> i'll gett a new offline branch. This mean that, as soon as the main server is reachable and the clone is online, i'll
> have to merge 2 branches. right? That's not really a problem, just need to know if i get it right.
>
> The OfflineExampleClone did not automatically merge the offline branch when it go online, and i add this myself:
>
> CDONet4jSession session = configuration.openNet4jSession();
> CDORepositoryInfo repositoryInfo = session.getRepositoryInfo();
> System.out.println("Connected to " + repositoryInfo.getName());
>
> transaction = session.openTransaction();
> createSessionListener
> session.addListener(new IListener()
> {
> private boolean justStarted = true;
> private boolean wasOffline;
>
> public void notifyEvent(IEvent event)
> {
> if (event instanceof CDOCommonRepository.StateChangedEvent)
> {
> CDOCommonRepository.StateChangedEvent e = (CDOCommonRepository.StateChangedEvent)event;
> State newState = e.getNewState();
> System.out.println("State changed to " + newState);
> if (autoMerging)
> {
> merge(session, newState);
> }
> }
> }
>
>
>
> The real problem is that after the first commit, and the creation of the first offline branch, if i reload my clone or
> simply open a new tranasction that will point to the MAIN and i can't see the previous modifications (that are in the
> offline branch). I surelly (well, more or less, see next point) can check if an offline branch is still open and
> switch to that, so until the clone stay offline i'll always work in a unique offline branch. But this is not really
> intuitive... the offline cdlone should act transparently as in Online state, where i can work as i were talking
> directly with the master. Is not it? (so, this is a "have i get it right?" and if i get it : "it can be improved")
>
> The previous was just a improvable thing. My problem is:
>
> If i do the follow:
>
> 1- start the clone in online mode (let it sync)
> 2- stop the master, the clone is now in offline mode
> 3- update some items and commit, offline branch created
> 4- start the master, the clone go online and merge the offline branch
> 5- stop the master, the clone go offline
> 6- update some more items, commit, another offline branch created
> 7- start the master, clone online, merge ???
>
> what offline branches should i merge? If i don't miss it a branch can't be closed, and i can't tell which is the
> Offline branches i have to merge to persist the last clone Offline-session.
>
> A way to solve this:
> - a way to delete a branch, an offline branch after merged is useless...
> - a way to close a branch, or at least tell if it has been modified since the last merge or creation.
>
> I hope I made ​​it clear, how can i solve this?
>
>
Re: [CDO] Offline Branching [message #964616 is a reply to message #960228] Tue, 30 October 2012 13:08 Go to previous message
Michele Preti is currently offline Michele Preti
Messages: 14
Registered: October 2012
Junior Member
This way seem to work perfectly, thanks.
Previous Topic:[CDO] Detecting whether a legacy object is being populated from revision data
Next Topic:[EMFT] Reloading resources in a transactional editing context
Goto Forum:
  


Current Time: Thu Apr 17 11:27:23 EDT 2014

Powered by FUDForum. Page generated in 0.02476 seconds