001/*
002 * (C) Copyright 2006-2011 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 *     Nuxeo - initial API and implementation
018 */
019
020package org.nuxeo.ecm.core.management;
021
022import org.nuxeo.ecm.core.management.api.ProbeInfo;
023import org.nuxeo.ecm.core.management.api.ProbeManager;
024import org.nuxeo.ecm.core.management.probes.ProbeInfoImpl;
025import org.nuxeo.ecm.core.management.probes.ProbeManagerImpl;
026import org.nuxeo.ecm.core.management.statuses.AdministrativeStatusManagerImpl;
027import org.nuxeo.runtime.api.Framework;
028import org.nuxeo.runtime.management.AbstractResourceFactory;
029import org.nuxeo.runtime.management.ObjectNameFactory;
030
031public class StatusesManagementFactory extends AbstractResourceFactory {
032
033    protected void doQualifyNames(ProbeInfoImpl info) {
034        info.setShortcutName(info.getDescriptor().getShortcut());
035        info.setQualifiedName(info.getDescriptor().getQualifiedName());
036        if (info.getQualifiedName() == null) {
037            info.setQualifiedName(ObjectNameFactory.formatQualifiedName(CoreManagementComponent.NAME)
038                    + ",status=probes,probe=" + info.getShortcutName());
039        }
040    }
041
042    @Override
043    public void registerResources() {
044
045        AdministrativeStatusManagerImpl adminStatus = Framework.getLocalService(AdministrativeStatusManagerImpl.class);
046        service.registerResource("adminStatus", ObjectNameFactory.formatQualifiedName(CoreManagementComponent.NAME)
047                + ",status=administrative", AdministrativeStatusManagerImpl.class, adminStatus);
048
049        ProbeManager runner = Framework.getLocalService(ProbeManager.class);
050        service.registerResource("probeStatus", ObjectNameFactory.formatQualifiedName(CoreManagementComponent.NAME)
051                + ",status=probes", ProbeManagerImpl.class, runner);
052        for (ProbeInfo info : runner.getAllProbeInfos()) {
053            doQualifyNames((ProbeInfoImpl) info);
054            service.registerResource(info.getShortcutName(), info.getQualifiedName(), ProbeInfoImpl.class, info);
055        }
056    }
057
058}