Skip to main content
summaryrefslogtreecommitdiffstats
blob: 75064d4ffe4447f76439ad14389a24903cddcebb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.net4j.util.concurrent;

import java.util.Collection;

/**
 * Support Multiple reads/no write and upgrade lock from read to write. Many context could request
 * {@link LockType#WRITE write} lock at the same time. It will privileges first context that has already a
 * {@link LockType#READ read} lock. If no one has any read lock, it's "first come first serve".
 * 
 * @author Eike Stepper
 * @since 3.0
 */
public interface IRWLockManager<OBJECT, CONTEXT>
{
  public static final int WAIT = 0;

  public static final int NO_WAIT = 1;

  public void lock(LockType type, CONTEXT context, Collection<? extends OBJECT> objectsToLock, long timeout)
      throws InterruptedException;

  public void lock(LockType type, CONTEXT context, OBJECT objectToLock, long timeout) throws InterruptedException;

  /**
   * Attempts to release for a given locktype, context and objects.
   * 
   * @throws IllegalMonitorStateException
   *           Unlocking objects without lock.
   */
  public void unlock(LockType type, CONTEXT context, Collection<? extends OBJECT> objectsToUnlock);

  /**
   * Attempts to release all locks(read and write) for a given context.
   */
  public void unlock(CONTEXT context);

  public boolean hasLock(LockType type, CONTEXT context, OBJECT objectToLock);

  public boolean hasLockByOthers(LockType type, CONTEXT context, OBJECT objectToLock);

  /**
   * @author Simon McDuff
   */
  public static enum LockType
  {
    WRITE, READ,

    /**
     * @since 3.2
     */
    OPTION
  }
}

Back to the top