alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Lucene example source code file (TwoPhaseCommit.java)

This example Lucene source code file (TwoPhaseCommit.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Lucene tags/keywords

io, ioexception, ioexception, string, string, twophasecommit, twophasecommit, util

The Lucene TwoPhaseCommit.java source code

package org.apache.lucene.util;

import java.io.IOException;
import java.util.Map;

/**
 * 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
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */

/**
 * An interface for implementations that support 2-phase commit. You can use
 * {@link TwoPhaseCommitTool} to execute a 2-phase commit algorithm over several
 * {@link TwoPhaseCommit}s.
 * 
 * @lucene.experimental
 */
public interface TwoPhaseCommit {

  /**
   * The first stage of a 2-phase commit. Implementations should do as much work
   * as possible in this method, but avoid actual committing changes. If the
   * 2-phase commit fails, {@link #rollback()} is called to discard all changes
   * since last successful commit.
   */
  public void prepareCommit() throws IOException;

  /**
   * Like {@link #commit()}, but takes an additional commit data to be included
   * w/ the commit.
   * <p>
   * <b>NOTE: some implementations may not support any custom data to be
   * included w/ the commit and may discard it altogether. Consult the actual
   * implementation documentation for verifying if this is supported.
   * 
   * @see #prepareCommit()
   */
  public void prepareCommit(Map<String, String> commitData) throws IOException;

  /**
   * The second phase of a 2-phase commit. Implementations should ideally do
   * very little work in this method (following {@link #prepareCommit()}, and
   * after it returns, the caller can assume that the changes were successfully
   * committed to the underlying storage.
   */
  public void commit() throws IOException;

  /**
   * Like {@link #commit()}, but takes an additional commit data to be included
   * w/ the commit.
   * 
   * @see #commit()
   * @see #prepareCommit(Map)
   */
  public void commit(Map<String, String> commitData) throws IOException;

  /**
   * Discards any changes that have occurred since the last commit. In a 2-phase
   * commit algorithm, where one of the objects failed to {@link #commit()} or
   * {@link #prepareCommit()}, this method is used to roll all other objects
   * back to their previous state.
   */
  public void rollback() throws IOException;

}

Other Lucene examples (source code examples)

Here is a short list of links related to this Lucene TwoPhaseCommit.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.