Package org.atomojo.app.admin

Source Code of org.atomojo.app.admin.RestartResource

/*
* RestartResource.java
*
* Created on November 27, 2007, 1:39 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package org.atomojo.app.admin;

import java.util.logging.Level;
import org.atomojo.app.App;
import org.atomojo.app.Storage;
import org.atomojo.app.db.DB;
import org.restlet.data.CharacterSet;
import org.restlet.data.MediaType;
import org.restlet.data.Status;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.ServerResource;

/**
*
* @author alex
*/
public class RestartResource extends ServerResource implements AdminXML
{
   /** Creates a new instance of SyncResource */
   public RestartResource() {
      setNegotiated(false);
   }
  
   public Representation get() {
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      final Storage storage = (Storage)getRequest().getAttributes().get(App.STORAGE_ATTR);
      try {
         db.stop();
         db.connect();
         getResponse().setStatus(Status.SUCCESS_OK);
         Representation rep = new StringRepresentation("<success xmlns='"+AdminXML.NAMESPACE+"'/>",MediaType.APPLICATION_XML);
         rep.setCharacterSet(CharacterSet.UTF_8);
         return rep;
      } catch (Exception ex) {
         getLogger().log(Level.SEVERE,"Failed to restart database.",ex);
         getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
         return new StringRepresentation("Failed to restart database.  Service may now be unavailable.");
      }
   }
  
  
}
TOP

Related Classes of org.atomojo.app.admin.RestartResource

TOP
Copyright © 2018 www.massapi.com. 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.