KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > management > deployment > deploy > SAStateHolderCreationTask


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2006 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: SAStateHolderCreationTask.java 154 6 oct. 06 ofabre $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.management.deployment.deploy;
23
24 import java.io.File JavaDoc;
25 import java.net.URI JavaDoc;
26 import java.util.HashMap JavaDoc;
27
28 import javax.jbi.management.LifeCycleMBean;
29
30 import org.objectweb.petals.jbi.management.deployment.DeploymentContextConstants;
31 import org.objectweb.petals.jbi.management.deployment.DeploymentUtils;
32 import org.objectweb.petals.jbi.management.systemstate.SystemState;
33 import org.objectweb.petals.processor.Task;
34 import org.objectweb.petals.repository.RepositoryService;
35 import org.objectweb.petals.tools.jbicommon.descriptor.JBIDescriptor;
36 import org.objectweb.petals.util.LoggingUtil;
37
38 /**
39  * This task creates state holder for service assembly
40  *
41  * @author ofabre - EBM Websourcing
42  *
43  */

44 public class SAStateHolderCreationTask implements Task {
45
46     /**
47      * JBI Container :: Recovery Service
48      */

49     protected SystemState recoverySrv;
50
51     /**
52      * Platform Component :: Repository Service
53      */

54     protected RepositoryService repositorySrv;
55
56     /**
57      * logger wrapper
58      */

59     protected LoggingUtil log;
60
61     public SAStateHolderCreationTask(SystemState recoverySrv,
62             RepositoryService repositorySrv, LoggingUtil log) {
63         super();
64         this.recoverySrv = recoverySrv;
65         this.repositorySrv = repositorySrv;
66         this.log = log;
67     }
68
69     public void execute(HashMap JavaDoc context) throws Exception JavaDoc {
70         JBIDescriptor descriptor = (JBIDescriptor) context
71                 .get(DeploymentContextConstants.SA_DESCRIPTOR);
72
73         URI JavaDoc saArchiveURI = (URI JavaDoc) context
74                 .get(DeploymentContextConstants.ARCHIVE_URI);
75
76         String JavaDoc saName = DeploymentUtils.getServiceAssemblyName(descriptor);
77
78         File JavaDoc file = DeploymentUtils.getArchiveFile(saArchiveURI);
79         File JavaDoc installedArchive = DeploymentUtils.getInstalledArchive(file);
80
81         recoverySrv.createServiceAssemblyStateHolder(saName, repositorySrv
82                 .getServiceAssemblyInstallRoot(saName).toURL().toString(),
83                 installedArchive.toURL().toString(), LifeCycleMBean.SHUTDOWN);
84
85     }
86
87     public void undo(HashMap JavaDoc context) {
88         JBIDescriptor descriptor = (JBIDescriptor) context
89                 .get(DeploymentContextConstants.SA_DESCRIPTOR);
90
91         try {
92             recoverySrv.deleteServiceAssemblyStateHolder(DeploymentUtils
93                     .getServiceAssemblyName(descriptor));
94         } catch (Exception JavaDoc e) {
95             String JavaDoc msg = "Failed to revert a SAStateHolderCreationTask";
96             log.error(msg, e);
97         }
98
99     }
100
101 }
102
Popular Tags