Lean  $LEAN_TAG$
IObjectStore.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
16 using System;
17 using QuantConnect.Packets;
18 using System.Collections.Generic;
19 using System.ComponentModel.Composition;
20 
22 {
23  /// <summary>
24  /// Provides object storage for data persistence.
25  /// </summary>
26  [InheritedExport(typeof(IObjectStore))]
27  public interface IObjectStore : IDisposable, IEnumerable<KeyValuePair<string, byte[]>>
28  {
29  /// <summary>
30  /// Event raised each time there's an error
31  /// </summary>
32  event EventHandler<ObjectStoreErrorRaisedEventArgs> ErrorRaised;
33 
34  /// <summary>
35  /// Initializes the object store
36  /// </summary>
37  /// <param name="userId">The user id</param>
38  /// <param name="projectId">The project id</param>
39  /// <param name="userToken">The user token</param>
40  /// <param name="controls">The job controls instance</param>
41  void Initialize(int userId, int projectId, string userToken, Controls controls);
42 
43  /// <summary>
44  /// Determines whether the store contains data for the specified path
45  /// </summary>
46  /// <param name="path">The object path</param>
47  /// <returns>True if the key was found</returns>
48  bool ContainsKey(string path);
49 
50  /// <summary>
51  /// Returns the object data for the specified key
52  /// </summary>
53  /// <param name="path">The object key</param>
54  /// <returns>A byte array containing the data</returns>
55  byte[] ReadBytes(string path);
56 
57  /// <summary>
58  /// Saves the object data for the specified path
59  /// </summary>
60  /// <param name="path">The object path</param>
61  /// <param name="contents">The object data</param>
62  /// <returns>True if the save operation was successful</returns>
63  bool SaveBytes(string path, byte[] contents);
64 
65  /// <summary>
66  /// Deletes the object data for the specified path
67  /// </summary>
68  /// <param name="path">The object path</param>
69  /// <returns>True if the delete operation was successful</returns>
70  bool Delete(string path);
71 
72  /// <summary>
73  /// Returns the file path for the specified path
74  /// </summary>
75  /// <param name="path">The object path</param>
76  /// <returns>The path for the file</returns>
77  string GetFilePath(string path);
78 
79  /// <summary>
80  /// Returns the file paths present in the object store. This is specially useful not to load the object store into memory
81  /// </summary>
82  ICollection<string> Keys { get; }
83 
84  /// <summary>
85  /// Will clear the object store state cache. This is useful when the object store is used concurrently by nodes which want to share information
86  /// </summary>
87  void Clear();
88  }
89 }