|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2017 - 2020 Deutsches Elektronen-Synchroton, |
| 2 | + * Copyright (c) 2017 - 2022 Deutsches Elektronen-Synchroton, |
3 | 3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
|
4 | 4 | *
|
5 | 5 | * This library is free software; you can redistribute it and/or modify
|
|
21 | 21 |
|
22 | 22 | import com.google.common.util.concurrent.Striped;
|
23 | 23 | import java.util.ArrayList;
|
| 24 | +import java.util.Collection; |
24 | 25 | import java.util.Iterator;
|
25 | 26 | import java.util.List;
|
26 | 27 | import java.util.Map;
|
27 | 28 | import java.util.concurrent.ConcurrentHashMap;
|
28 | 29 | import java.util.concurrent.locks.Lock;
|
| 30 | +import java.util.stream.Collectors; |
29 | 31 | import org.dcache.nfs.ChimeraNFSException;
|
30 | 32 | import org.dcache.nfs.status.BadStateidException;
|
31 | 33 | import org.dcache.nfs.status.InvalException;
|
@@ -84,6 +86,9 @@ public StateOwner getOwner() {
|
84 | 86 | return owner;
|
85 | 87 | }
|
86 | 88 |
|
| 89 | + public NFS4Client getClient() { |
| 90 | + return client; |
| 91 | + } |
87 | 92 | }
|
88 | 93 |
|
89 | 94 | /**
|
@@ -251,4 +256,18 @@ public int getShareAccess(NFS4Client client, Inode inode, stateid4 stateid) thro
|
251 | 256 | lock.unlock();
|
252 | 257 | }
|
253 | 258 | }
|
| 259 | + |
| 260 | + /** |
| 261 | + * Get all currently open files with associated clients. The resulting map contains file's inodes |
| 262 | + * as key and collection of nfs clients that have this file opened as a value. |
| 263 | + * |
| 264 | + * @return map of all open files. |
| 265 | + */ |
| 266 | + public Map<Inode, Collection<NFS4Client>> getOpenFiles() { |
| 267 | + return files.entrySet().stream() |
| 268 | + .collect(Collectors.toMap( |
| 269 | + e -> Inode.forFile(e.getKey().getOpaque()), |
| 270 | + e -> e.getValue().stream().map(OpenState::getClient).collect(Collectors.toSet())) |
| 271 | + ); |
| 272 | + } |
254 | 273 | }
|
0 commit comments