You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@bookkeeper.apache.org by gi...@git.apache.org on 2017/07/20 12:40:51 UTC

[GitHub] eolivelli commented on a change in pull request #266: Issue 265: Add persistable bookie status

eolivelli commented on a change in pull request #266: Issue 265: Add persistable bookie status
URL: https://github.com/apache/bookkeeper/pull/266#discussion_r128501094
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieStatus.java
 ##########
 @@ -0,0 +1,246 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.bookkeeper.bookie;
+
+import static com.google.common.base.Charsets.UTF_8;
+import static org.apache.bookkeeper.util.BookKeeperConstants.BOOKIE_STATUS_FILENAME;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The status object represents the current status of a bookie instance.
+ */
+public class BookieStatus {
+    static Logger LOG = LoggerFactory.getLogger(BookieStatus.class);
+    static final int CURRENT_STATUS_LAYOUT_VERSION = 1;
+
+    enum BookieMode {
+        READ_ONLY,
+        READ_WRITE;
+    }
+
+    private final static long INVALID_UPDATE_TIME = -1;
+
+    private int layoutVersion;
+    private long lastUpdateTime;
+    private BookieMode bookieMode;
+
+
+    BookieStatus() {
+        this.bookieMode = BookieMode.READ_WRITE;
+        this.layoutVersion = CURRENT_STATUS_LAYOUT_VERSION;
+        this.lastUpdateTime = INVALID_UPDATE_TIME;
+    }
+
+    private synchronized BookieMode getBookieMode() {
+        return bookieMode;
+    }
+
+    public synchronized boolean isInWritable() {
+        return bookieMode.equals(BookieMode.READ_WRITE);
+    }
+
+    synchronized boolean setToWritableMode() {
+        if (!bookieMode.equals(BookieMode.READ_WRITE)) {
+            bookieMode = BookieMode.READ_WRITE;
+            this.lastUpdateTime = System.currentTimeMillis();
+            return true;
+        }
+        return false;
+    }
+
+    synchronized boolean isInReadOnlyMode() {
+        return bookieMode.equals(BookieMode.READ_ONLY);
 
 Review comment:
   Can't we use '==' for enums ?
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services