PageRenderTime 61ms CodeModel.GetById 26ms app.highlight 30ms RepoModel.GetById 1ms app.codeStats 0ms

/jboss-as-7.1.1.Final/controller/src/main/java/org/jboss/as/controller/persistence/ConfigurationPersister.java

#
Java | 145 lines | 34 code | 20 blank | 91 comment | 0 complexity | ab6a4d24eb9f4e3960a6d193ef339ddb MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1/*
  2 * JBoss, Home of Professional Open Source.
  3 * Copyright 2011, Red Hat, Inc., and individual contributors
  4 * as indicated by the @author tags. See the copyright.txt file in the
  5 * distribution for a full listing of individual contributors.
  6 *
  7 * This is free software; you can redistribute it and/or modify it
  8 * under the terms of the GNU Lesser General Public License as
  9 * published by the Free Software Foundation; either version 2.1 of
 10 * the License, or (at your option) any later version.
 11 *
 12 * This software is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15 * Lesser General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU Lesser General Public
 18 * License along with this software; if not, write to the Free
 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21 */
 22
 23package org.jboss.as.controller.persistence;
 24
 25import java.io.OutputStream;
 26import java.util.Collections;
 27import java.util.List;
 28import java.util.Set;
 29
 30import org.jboss.as.controller.PathAddress;
 31import org.jboss.dmr.ModelNode;
 32
 33/**
 34 * The configuration persister for a model.
 35 *
 36 * @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
 37 */
 38public interface ConfigurationPersister {
 39
 40    /**
 41     * Callback for use by callers to {@link ConfigurationPersister#store(org.jboss.dmr.ModelNode, java.util.Set)}
 42     * to control whether the stored model should be flushed to permanent storage.
 43     */
 44    interface PersistenceResource {
 45
 46        /**
 47         * Flush the stored model to permanent storage.
 48         */
 49        void commit();
 50
 51        /**
 52         * Discard the changes.
 53         */
 54        void rollback();
 55    }
 56
 57    /**
 58     * Persist the given configuration model.
 59     *
 60     * @param model the model to persist
 61     * @param affectedAddresses
 62     *
 63     * @return callback to use to control whether the stored model should be flushed to persistent storage
 64     */
 65    PersistenceResource store(ModelNode model, Set<PathAddress> affectedAddresses) throws ConfigurationPersistenceException;
 66
 67    /**
 68     * Marshals the given configuration model to XML, writing to the given stream.
 69     *
 70     * @param model  the model to persist
 71     * @param output the stream
 72     * @throws ConfigurationPersistenceException
 73     */
 74    void marshallAsXml(final ModelNode model, final OutputStream output) throws ConfigurationPersistenceException;
 75
 76    /**
 77     * Load the configuration model, returning it as a list of updates to be
 78     * executed by the controller.
 79     */
 80    List<ModelNode> load() throws ConfigurationPersistenceException;
 81
 82    /**
 83     * Called once the xml has been successfully parsed, translated into updates, executed in the target controller
 84     * and all services have started successfully
 85     */
 86    void successfulBoot() throws ConfigurationPersistenceException;
 87
 88    /**
 89     * Take a snapshot of the current configuration
 90     *
 91     * @return the location of the snapshot
 92     * @return the file location of the snapshot
 93     * @throws ConfigurationPersistenceException if a problem happened when creating the snapshot
 94     */
 95    String snapshot() throws ConfigurationPersistenceException;
 96
 97    /**
 98     * Gets the names of the snapshots in the snapshots directory
 99     *
100     * @return the snapshot info. This will never return null
101     */
102    SnapshotInfo listSnapshots();
103
104    /**
105     * Deletes a snapshot using its name.
106     *
107     * @param name the name of the snapshot (as returned by {@link SnapshotInfo#names()} returned from {@link #listSnapshots()}. The whole name is not
108     * needed, just enough to uniquely identify it.
109     * @throws IllegalArgumentException if there is no snapshot with the given name, or if the name resolves to more than one snapshot.
110     */
111    void deleteSnapshot(String name);
112
113    /**
114     * Contains the info about the configuration snapshots
115     */
116    public interface SnapshotInfo {
117        /**
118         * Gets the snapshots directory
119         *
120         * @return the snapshots directory
121         */
122        String getSnapshotDirectory();
123
124        /**
125         * Gets the names of the snapshot files in the snapshots directory
126         *
127         * @return the snapshot names. If there are none, an empty list is returned
128         */
129        List<String> names();
130    }
131
132    SnapshotInfo NULL_SNAPSHOT_INFO = new SnapshotInfo() {
133
134        @Override
135        public List<String> names() {
136            return Collections.emptyList();
137        }
138
139        @Override
140        public String getSnapshotDirectory() {
141            return "";
142        }
143    };
144
145}