PageRenderTime 180ms CodeModel.GetById 22ms RepoModel.GetById 0ms 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. package org.jboss.as.controller.persistence;
  23. import java.io.OutputStream;
  24. import java.util.Collections;
  25. import java.util.List;
  26. import java.util.Set;
  27. import org.jboss.as.controller.PathAddress;
  28. import org.jboss.dmr.ModelNode;
  29. /**
  30. * The configuration persister for a model.
  31. *
  32. * @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
  33. */
  34. public interface ConfigurationPersister {
  35. /**
  36. * Callback for use by callers to {@link ConfigurationPersister#store(org.jboss.dmr.ModelNode, java.util.Set)}
  37. * to control whether the stored model should be flushed to permanent storage.
  38. */
  39. interface PersistenceResource {
  40. /**
  41. * Flush the stored model to permanent storage.
  42. */
  43. void commit();
  44. /**
  45. * Discard the changes.
  46. */
  47. void rollback();
  48. }
  49. /**
  50. * Persist the given configuration model.
  51. *
  52. * @param model the model to persist
  53. * @param affectedAddresses
  54. *
  55. * @return callback to use to control whether the stored model should be flushed to persistent storage
  56. */
  57. PersistenceResource store(ModelNode model, Set<PathAddress> affectedAddresses) throws ConfigurationPersistenceException;
  58. /**
  59. * Marshals the given configuration model to XML, writing to the given stream.
  60. *
  61. * @param model the model to persist
  62. * @param output the stream
  63. * @throws ConfigurationPersistenceException
  64. */
  65. void marshallAsXml(final ModelNode model, final OutputStream output) throws ConfigurationPersistenceException;
  66. /**
  67. * Load the configuration model, returning it as a list of updates to be
  68. * executed by the controller.
  69. */
  70. List<ModelNode> load() throws ConfigurationPersistenceException;
  71. /**
  72. * Called once the xml has been successfully parsed, translated into updates, executed in the target controller
  73. * and all services have started successfully
  74. */
  75. void successfulBoot() throws ConfigurationPersistenceException;
  76. /**
  77. * Take a snapshot of the current configuration
  78. *
  79. * @return the location of the snapshot
  80. * @return the file location of the snapshot
  81. * @throws ConfigurationPersistenceException if a problem happened when creating the snapshot
  82. */
  83. String snapshot() throws ConfigurationPersistenceException;
  84. /**
  85. * Gets the names of the snapshots in the snapshots directory
  86. *
  87. * @return the snapshot info. This will never return null
  88. */
  89. SnapshotInfo listSnapshots();
  90. /**
  91. * Deletes a snapshot using its name.
  92. *
  93. * @param name the name of the snapshot (as returned by {@link SnapshotInfo#names()} returned from {@link #listSnapshots()}. The whole name is not
  94. * needed, just enough to uniquely identify it.
  95. * @throws IllegalArgumentException if there is no snapshot with the given name, or if the name resolves to more than one snapshot.
  96. */
  97. void deleteSnapshot(String name);
  98. /**
  99. * Contains the info about the configuration snapshots
  100. */
  101. public interface SnapshotInfo {
  102. /**
  103. * Gets the snapshots directory
  104. *
  105. * @return the snapshots directory
  106. */
  107. String getSnapshotDirectory();
  108. /**
  109. * Gets the names of the snapshot files in the snapshots directory
  110. *
  111. * @return the snapshot names. If there are none, an empty list is returned
  112. */
  113. List<String> names();
  114. }
  115. SnapshotInfo NULL_SNAPSHOT_INFO = new SnapshotInfo() {
  116. @Override
  117. public List<String> names() {
  118. return Collections.emptyList();
  119. }
  120. @Override
  121. public String getSnapshotDirectory() {
  122. return "";
  123. }
  124. };
  125. }