Package org.atomojo.app.db

Examples of org.atomojo.app.db.SyncProcess


               ItemDestination dest = new WriterItemDestination(out,"UTF-8");
               ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
               dest.send(constructor.createDocument());
               dest.send(constructor.createElement(AdminXML.NM_SYNC_PROCESSES));
               while (procs.hasNext()) {
                  SyncProcess proc = procs.next();
                  proc.marshall();
                  DocumentSource.generate(proc.getElement(),false,dest);
               }
               dest.send(constructor.createElementEnd(AdminXML.NM_SYNC_PROCESSES));
               dest.send(constructor.createDocumentEnd());
               out.flush();
               out.close();
View Full Code Here


        
         Name [] roots = { AdminXML.NM_PUSH , AdminXML.NM_PULL };
         parser.parse(entity,AdminApplication.createAdminDocumentDestination(dest,roots));
         doc = dest.getDocument();
         Element top = doc.getDocumentElement();
         SyncProcess proc = new SyncProcess(db,top);
         if (proc.exists()) {
            getResponse().setStatus(Status.CLIENT_ERROR_CONFLICT);
            return new StringRepresentation("Process with name "+proc.getName()+" already exists.");
         }
         if (proc.getRemoteApp()==null) {
            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation("The remote app service with name "+top.getAttributeValue("remote")+" does not exist.");
         }
         if (proc.getSyncTarget()==null) {
            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation("The local target with name "+top.getAttributeValue("target")+" does not exist.");
         }
         if (proc.create()) {
            getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
            Reference ref = new Reference(getRequest().getResourceRef().toString()+"/"+proc.getName());
            getResponse().setLocationRef(ref);
            return null;
         } else {
            getContext().getLogger().severe("Cannot store XML for sync process");
            getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
View Full Code Here

  
   public Representation get()
   {
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      final String name = getRequest().getAttributes().get("name").toString();
      SyncProcess proc = new SyncProcess(db,name);
      if (proc.exists()) {
         return proc.getRepresentation();
      } else {
         getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
         return null;
      }
   }
View Full Code Here

      try {
         DocumentDestination dest = new DocumentDestination();
         Name [] names = { AdminXML.NM_PULL, AdminXML.NM_PUSH };
         parser.parse(entity,AdminApplication.createAdminDocumentDestination(dest,names));
         doc = dest.getDocument();
         SyncProcess proc = new SyncProcess(db,doc.getDocumentElement());
         String lname = proc.getName();
         if (!lname.equals(name)) {
            getResponse().setStatus(Status.CLIENT_ERROR_EXPECTATION_FAILED);
            return new StringRepresentation("Cannot change the name of the target.");
         }
         if (proc.exists()) {
            if (proc.update()) {
               getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
               return null;
            } else {
               getContext().getLogger().severe("Cannot store XML for remote app.");
               getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
View Full Code Here

   }
  
   public Representation delete() {
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      final String name = getRequest().getAttributes().get("name").toString();
      SyncProcess proc = new SyncProcess(db,name);
      if (proc.exists()) {
         if (proc.delete()) {
            getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
         } else {
            getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
         }
      } else {
View Full Code Here

                  RemoteApp app = new RemoteApp(db,"backup");
                  app.setIntrospection(introspectionURI);
                  app.setRoot(dbDir.toURI());

                  SyncTarget target = new SyncTarget(db,"");
                  SyncProcess proc = new SyncProcess(db,"restore",true,target,app,null);

                  PullSynchronizer restore = new PullSynchronizer(getLogger(),getApplication().getMetadataService(),user,db,storage,proc);
                  restore.setAdditive(false);
                  try {
                     restore.sync();
View Full Code Here

            app.setRoot(dir.toURI());
         }
        
         SyncTarget target = new SyncTarget(db,"");
        
         SyncProcess proc = new SyncProcess(db,"restore",true,target,app,null);
        
         User user = (User)getRequest().getAttributes().get(App.USER_ATTR);
        
         try {
            PullSynchronizer restore = new PullSynchronizer(getContext().getLogger(),getApplication().getMetadataService(),user,db,storage,proc);
View Full Code Here

   {
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      final Storage storage = (Storage)getRequest().getAttributes().get(App.STORAGE_ATTR);
      final String name = getRequest().getAttributes().get("name").toString();

      SyncProcess proc = db.getSyncProcess(name);
     
      if (proc!=null) {
         Synchronizer sync = null;
         if (proc.isPullSynchronization()) {
            User user = (User)getRequest().getAttributes().get(App.USER_ATTR);
            sync = new PullSynchronizer(getContext().getLogger(),getApplication().getMetadataService(),user,db,storage,proc);
            ((PullSynchronizer)sync).setAdditive(proc.isAdditive());
         } else {
            sync = new PushSynchronizer(getContext().getLogger(),db,storage,proc);
         }
         try {
            sync.setSynchronizationAt(new Date());
View Full Code Here

      log.fine("Checking for targets to synchronize...");
      final Date thisSync = new Date();
      try {
         Iterator<SyncProcess> procs = db.getSyncProcesses();
         while (procs.hasNext()) {
            SyncProcess proc = procs.next();
            try {
               proc.unmarshall();
               if (proc.isPullSynchronization()) {
                  continue;
               }
               proc.getSyncTarget().unmarshall();
               proc.getRemoteApp().unmarshall();
              
               log.info("Synchronizing process "+proc.getName()+": target="+proc.getSyncTarget().getName()+", app="+proc.getRemoteApp().getName());
               PushSynchronizer push = new PushSynchronizer(log,db,storage,proc);
               push.setSynchronizationAt(thisSync);
               try {
                  push.sync();
               } catch (TargetNotAvailableException ex) {
                  allOK.set(false);
                  log.warning(ex.getMessage());
               } catch (SyncException ex) {
                  log.log(Level.SEVERE,"Failure to sync process "+proc.getName(),ex);
                  allOK.set(false);
               }
               log.info("Finished sync process "+proc.getName());
            } catch (Exception ex) {
               // No error should happen.. but hey...
               log.log(Level.SEVERE,"Cannot unmarshall document.",ex);
               continue;
            }
View Full Code Here

TOP

Related Classes of org.atomojo.app.db.SyncProcess

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.