Repository navigation
[NETBEANS-4962] Adding ability to disable hard-locking files using lock files. #6639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lahodaj
wants to merge
6
commits into
apache:master
Choose a base branch
from
lahodaj:in-memory-hard-lock
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ba60631
[NETBEANS-4962] Adding ability to disable hard-locking files using lo…
lahodaj c4bc50d
Dropping HardLockPath.
35e4244
Putting the classes to the package level.
c05aba5
API description.
4d7d058
Improving wording.
c4d033c
Adding api usecase links as suggested.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...s/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FileBaseHardLockRegistry.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package org.netbeans.modules.masterfs.filebasedfs.fileobjects; | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileInputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.OutputStream; | ||
| import java.nio.file.Files; | ||
| import org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager; | ||
| import org.openide.util.Exceptions; | ||
| import org.openide.util.lookup.ServiceProvider; | ||
|
|
||
| @ServiceProvider(service = HardLockRegistry.class, position = 100) | ||
| public final class FileBaseHardLockRegistry implements HardLockRegistry { | ||
|
|
||
| public void doHardLock(File hardLock, String absolutePath) throws IOException { | ||
| hardLock.getParentFile().mkdirs(); | ||
| hardLock.createNewFile(); | ||
| try (OutputStream os = Files.newOutputStream(hardLock.toPath())) { | ||
| os.write(absolutePath.getBytes()); | ||
| } | ||
| } | ||
|
|
||
| public boolean doHardUnlock(File hardLock) { | ||
| return hardLock.delete(); | ||
| } | ||
|
|
||
| public boolean hardLockExists(File hardLock) throws IOException { | ||
| return FileChangedManager.getInstance().exists(hardLock); | ||
| } | ||
|
|
||
| public String getHardLockContent(File hardLock) { | ||
| if (FileChangedManager.getInstance().exists(hardLock)) { | ||
| try (InputStream is = new FileInputStream(hardLock)) { | ||
| byte[] path = new byte[is.available()]; | ||
| if (path.length > 0 && is.read(path) == path.length) { | ||
| return new String(path); | ||
| } | ||
| } catch (IOException ex) { | ||
| Exceptions.printStackTrace(ex); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| } |
48 changes: 48 additions & 0 deletions
48
.../masterfs/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/HardLockRegistry.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package org.netbeans.modules.masterfs.filebasedfs.fileobjects; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import org.openide.util.Lookup; | ||
|
|
||
| /** A pluggable hard lock handler. | ||
| * @see <a href="@TOP@/architecture-summary.html#lookup-disable.LCK.files">the API usecase.</a>. | ||
| */ | ||
| public interface HardLockRegistry { | ||
|
|
||
| public static HardLockRegistry getInstance() { | ||
| return HardLockRegistryInstance.INSTANCE; | ||
| } | ||
|
|
||
| public void doHardLock(File hardLock, String absolutePath) throws IOException; | ||
|
|
||
| public boolean doHardUnlock(File hardLock); | ||
|
|
||
| public boolean hardLockExists(File hardLock) throws IOException; | ||
|
|
||
| public String getHardLockContent(File hardLock); | ||
|
|
||
| } | ||
|
|
||
| //init the HardLockRegistry instance lazily: | ||
| final class HardLockRegistryInstance { | ||
| public static final HardLockRegistry INSTANCE = Lookup.getDefault().lookup(HardLockRegistry.class); | ||
| } | ||
|
|
67 changes: 67 additions & 0 deletions
67
...s/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/InMemoryHardLockRegistry.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package org.netbeans.modules.masterfs.filebasedfs.fileobjects; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.file.Path; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
| import org.openide.util.Exceptions; | ||
| import org.openide.util.lookup.ServiceProvider; | ||
|
|
||
| @ServiceProvider(service = HardLockRegistry.class, position = 1000) | ||
| public final class InMemoryHardLockRegistry implements HardLockRegistry { | ||
|
|
||
| private static final Logger LOGGER = Logger.getLogger(InMemoryHardLockRegistry.class.getName()); | ||
| private final ConcurrentHashMap<String, String> hardLocks2Content = new ConcurrentHashMap<>(); | ||
|
|
||
| private static String getKey(File hardLock) throws IOException { | ||
| Path realParentPath = hardLock.toPath().getParent().toRealPath(); | ||
| return realParentPath.resolve(hardLock.getName()).toString(); | ||
| } | ||
|
|
||
| public void doHardLock(File hardLock, String absolutePath) throws IOException { | ||
| hardLocks2Content.put(getKey(hardLock), absolutePath); | ||
| } | ||
|
|
||
| public boolean doHardUnlock(File hardLock) { | ||
| try { | ||
| return hardLocks2Content.remove(getKey(hardLock)) != null; | ||
| } catch (IOException ex) { | ||
| LOGGER.log(Level.FINE, null, ex); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| public boolean hardLockExists(File hardLock) throws IOException { | ||
| return hardLocks2Content.containsKey(getKey(hardLock)); | ||
| } | ||
|
|
||
| public String getHardLockContent(File hardLock) { | ||
| try { | ||
| return hardLocks2Content.get(getKey(hardLock)); | ||
| } catch (IOException ex) { | ||
| Exceptions.printStackTrace(ex); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a link to the "a name" reference to https://github.com/apache/netbeans/pull/6639/changes#r4344525386 - it would be something like: