Browse Source

Add a listener for changes to a DfsObjDatabase's pack files

Intended for cross-request use, so only refers to
DfsRepositoryDescriptions rather than DfsRepositorys.

Change-Id: I2633e472c9264d91d632069f608d53d4bdd0fc09
stable-1.2
Dave Borowitz 13 years ago committed by Shawn O. Pearce
parent
commit
0f8e486a4d
  1. 17
      org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java
  2. 60
      org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPacksChangedEvent.java
  3. 57
      org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPacksChangedListener.java

17
org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java

@ -147,7 +147,7 @@ public abstract class DfsObjDatabase extends ObjectDatabase {
} }
/** /**
* List all available pack files in the repository. * Scan and list all available pack files in the repository.
* *
* @return list of available packs. The returned array is shared with the * @return list of available packs. The returned array is shared with the
* implementation and must not be modified by the caller. * implementation and must not be modified by the caller.
@ -163,6 +163,16 @@ public abstract class DfsObjDatabase extends ObjectDatabase {
return repository; return repository;
} }
/**
* List currently known pack files in the repository, without scanning.
*
* @return list of available packs. The returned array is shared with the
* implementation and must not be modified by the caller.
*/
public DfsPackFile[] getCurrentPacks() {
return packList.get().packs;
}
/** /**
* Generate a new unique name for a pack file. * Generate a new unique name for a pack file.
* *
@ -318,8 +328,8 @@ public abstract class DfsObjDatabase extends ObjectDatabase {
} }
private PackList scanPacks(final PackList original) throws IOException { private PackList scanPacks(final PackList original) throws IOException {
synchronized (packList) {
PackList o, n; PackList o, n;
synchronized (packList) {
do { do {
o = packList.get(); o = packList.get();
if (o != original) { if (o != original) {
@ -332,8 +342,9 @@ public abstract class DfsObjDatabase extends ObjectDatabase {
if (n == o) if (n == o)
return n; return n;
} while (!packList.compareAndSet(o, n)); } while (!packList.compareAndSet(o, n));
return n;
} }
getRepository().fireEvent(new DfsPacksChangedEvent());
return n;
} }
private PackList scanPacksImpl(PackList old) throws IOException { private PackList scanPacksImpl(PackList old) throws IOException {

60
org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPacksChangedEvent.java

@ -0,0 +1,60 @@
/*
* Copyright (C) 2011, Google Inc.
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Distribution License v1.0 which
* accompanies this distribution, is reproduced below, and is
* available at http://www.eclipse.org/org/documents/edl-v10.php
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* - Neither the name of the Eclipse Foundation, Inc. nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.storage.dfs;
import org.eclipse.jgit.events.RepositoryEvent;
/** Describes a change to the list of packs in a {@link DfsRepository}. */
public class DfsPacksChangedEvent
extends RepositoryEvent<DfsPacksChangedListener> {
@Override
public Class<DfsPacksChangedListener> getListenerType() {
return DfsPacksChangedListener.class;
}
@Override
public void dispatch(DfsPacksChangedListener listener) {
listener.onPacksChanged(this);
}
}

57
org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPacksChangedListener.java

@ -0,0 +1,57 @@
/*
* Copyright (C) 2011, Google Inc.
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Distribution License v1.0 which
* accompanies this distribution, is reproduced below, and is
* available at http://www.eclipse.org/org/documents/edl-v10.php
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* - Neither the name of the Eclipse Foundation, Inc. nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.storage.dfs;
import org.eclipse.jgit.events.RepositoryListener;
/** Receives {@link DfsPacksChangedEvent}s. */
public interface DfsPacksChangedListener extends RepositoryListener {
/**
* Invoked when all packs in a repository are listed.
*
* @param event
* information about the packs.
*/
void onPacksChanged(DfsPacksChangedEvent event);
}
Loading…
Cancel
Save