1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819package org.apache.giraph.ooc.command;
2021import org.apache.giraph.ooc.OutOfCoreEngine;
22import org.apache.giraph.ooc.data.DiskBackedMessageStore;
2324import java.io.IOException;
2526importstatic com.google.common.base.Preconditions.checkState;
2728/**29 * IOCommand to store incoming message of a particular partition.30 */31publicclassStoreIncomingMessageIOCommandextendsIOCommand {
32/**33 * Constructor34 *35 * @param oocEngine out-of-core engine36 * @param partitionId id of the partition to store its incoming messages37 */38publicStoreIncomingMessageIOCommand(OutOfCoreEngine oocEngine,
39int partitionId) {
40super(oocEngine, partitionId);
41 }
4243 @Override
44publicboolean execute() throws IOException {
45boolean executed = false;
46if (oocEngine.getMetaPartitionManager()
47 .startOffloadingMessages(partitionId)) {
48DiskBackedMessageStore messageStore =
49 (DiskBackedMessageStore)
50 oocEngine.getServerData().getIncomingMessageStore();
51 checkState(messageStore != null);
52 numBytesTransferred +=
53 messageStore.offloadPartitionData(partitionId);
54 oocEngine.getMetaPartitionManager().doneOffloadingMessages(partitionId);
55 executed = true;
56 }
57return executed;
58 }
5960 @Override
61publicIOCommandType getType() {
62return IOCommandType.STORE_MESSAGE;
63 }
6465 @Override
66public String toString() {
67return"StoreIncomingMessageIOCommand: (partitionId = " + partitionId + ")";
68 }
69 }