• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *       http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.cloud;
18 
19 /**
20  * Implementation of this interface can persist their state and restore from it.
21  *
22  * <p>A typical capture usage:
23  *
24  * <pre>{@code
25  * X restorableObj; // X instanceof Restorable<X>
26  * RestorableState<X> state = restorableObj.capture();
27  * .. persist state
28  * }</pre>
29  *
30  * <p>A typical restore usage:
31  *
32  * <pre>{@code
33  * RestorableState<X> state = ... // read from persistence
34  * X restorableObj = state.restore();
35  * ...
36  * }</pre>
37  *
38  * @param <T> the restorable object's type
39  */
40 public interface Restorable<T extends Restorable<T>> {
41 
42   /**
43    * Captures the state of this object.
44    *
45    * @return a {@link RestorableState} instance that contains the state for this object and can
46    *     restore it afterwards.
47    */
capture()48   RestorableState<T> capture();
49 }
50