001/* 002 * (C) Copyright 2006-2008 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thierry Delprat 018 */ 019package org.nuxeo.ecm.webapp.seam; 020 021import java.util.Set; 022 023import org.nuxeo.ecm.platform.ui.web.restAPI.BaseStatelessNuxeoRestlet; 024import org.restlet.Request; 025import org.restlet.Response; 026import org.restlet.data.MediaType; 027 028/** 029 * Restlet to trigger the reloading. (can not be done directly from a Seam bean without messing up JSF scopes). 030 * 031 * @author tiry 032 */ 033public class NuxeoSeamHotReloadRestTrigger extends BaseStatelessNuxeoRestlet { 034 035 @Override 036 protected void doHandleStatelessRequest(Request req, Response res) { 037 logDeprecation(); 038 039 StringBuffer sb = new StringBuffer(); 040 041 if (!SeamHotReloadHelper.isHotReloadEnabled()) { 042 sb.append("This operation is not permitted"); 043 } else { 044 045 long t0 = System.currentTimeMillis(); 046 Set<String> reloadedComponents = SeamHotReloadHelper.reloadSeamComponents(getHttpRequest(req)); 047 long t1 = System.currentTimeMillis(); 048 049 if (reloadedComponents != null) { 050 sb.append("Reloaded "); 051 sb.append(reloadedComponents.size()); 052 sb.append(" Seam components in "); 053 sb.append(t1 - t0); 054 sb.append("ms"); 055 sb.append("\n"); 056 057 for (String cn : reloadedComponents) { 058 sb.append(" "); 059 sb.append(cn); 060 sb.append("\n"); 061 } 062 } else { 063 Set<String> reloadableComponents = SeamHotReloadHelper.getHotDeployableComponents(getHttpRequest(req)); 064 if (reloadableComponents == null || reloadableComponents.size() == 0) { 065 sb.append("Nothing to reload"); 066 } else { 067 sb.append(reloadableComponents.size()); 068 sb.append(" reloadable Seam Components\n"); 069 sb.append("But nothing to reload (classes are up to date)"); 070 } 071 } 072 } 073 res.setEntity(sb.toString(), MediaType.TEXT_PLAIN); 074 } 075 076}