Skip to content

Commit 8663c30

Browse files
committed
Java shim / QFS access:
* Implement new style java cleanup by use ref.Cleaner, while retaining the old style cleanup for backward compatibility. * Rename all native classes by adding Base suffix. * Implement two different subclasses for each of KfsAccess, KfsInputChannel, and KfsOutputChannel, one for the old style cleanup and one for the new style cleanup. * Reformat the code to match the new style. * Eliminate java compiler warnings.
1 parent fbca36b commit 8663c30

File tree

10 files changed

+849
-789
lines changed

10 files changed

+849
-789
lines changed

src/cc/access/qfs_access_jni.cc

Lines changed: 142 additions & 151 deletions
Large diffs are not rendered by default.

src/java/qfs-access-9/src/main/java/com/quantcast/qfs/access/KfsAccess.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* License for the specific language governing permissions and limitations under
2323
* the License.
2424
*
25-
* \brief Java wrappers to get to the KFS client.
25+
* \brief QFS access java 9 style cleanup.
2626
*/
2727
package com.quantcast.qfs.access;
2828

@@ -37,25 +37,29 @@ static void registerCleanup(Object obj, Runnable action) {
3737
cleaner.register(obj, action);
3838
}
3939

40-
private void register() {
40+
private static void registerCleanupSelf(KfsAccess ka) {
4141
// Ensure that the native resource is cleaned up when this object is
4242
// garbage collected.
43-
// Make sure that this is not referenced by the cleaner closure
43+
// Make sure that this and ka are not referenced by the cleaner closure
4444
// otherwise it will never be cleaned up.
45-
final long ptr = getCPtr();
46-
registerCleanup(this, () -> {
45+
final long ptr = ka.getCPtr();
46+
registerCleanup(ka, () -> {
4747
destroy(ptr);
4848
});
4949
}
5050

51+
private void registerCleanupConstructed() {
52+
registerCleanupSelf(this);
53+
}
54+
5155
public KfsAccess(String configFn) throws IOException {
5256
super(configFn);
53-
register();
57+
registerCleanupConstructed();
5458
}
5559

5660
public KfsAccess(String metaServerHost,
5761
int metaServerPort) throws IOException {
5862
super(metaServerHost, metaServerPort);
59-
register();
63+
registerCleanupConstructed();
6064
}
6165
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* $Id$
3+
*
4+
* Created 2025/04/20
5+
*
6+
* @author: Mike Ovsiannikov (Quantcast Corporation)
7+
*
8+
* Copyright 2025 Quantcast Corporation. All rights reserved.
9+
* Copyright 2007 Kosmix Corp.
10+
*
11+
* This file is part of Kosmos File System (KFS).
12+
*
13+
* Licensed under the Apache License, Version 2.0
14+
* (the "License"); you may not use this file except in compliance with
15+
* the License. You may obtain a copy of the License at
16+
*
17+
* http://www.apache.org/licenses/LICENSE-2.0
18+
*
19+
* Unless required by applicable law or agreed to in writing, software
20+
* distributed under the License is distributed on an "AS IS" BASIS,
21+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
22+
* implied. See the License for the specific language governing
23+
* permissions and limitations under the License.
24+
*
25+
* \brief Input channel java 9 style cleanup.
26+
*/
27+
package com.quantcast.qfs.access;
28+
29+
final public class KfsInputChannel extends KfsInputChannelBase {
30+
31+
KfsInputChannel(KfsAccessBase ka, int fd) {
32+
super(ka, fd);
33+
registerCleanup();
34+
}
35+
36+
private void registerCleanup() {
37+
KfsAccess.registerCleanup(this, state);
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* $Id$
3+
*
4+
* Created 2025/04/20
5+
*
6+
* @author: Mike Ovsiannikov (Quantcast Corporation)
7+
*
8+
* Copyright 2025 Quantcast Corporation. All rights reserved.
9+
* Copyright 2007 Kosmix Corp.
10+
*
11+
* This file is part of Kosmos File System (KFS).
12+
*
13+
* Licensed under the Apache License, Version 2.0
14+
* (the "License"); you may not use this file except in compliance with
15+
* the License. You may obtain a copy of the License at
16+
*
17+
* http://www.apache.org/licenses/LICENSE-2.0
18+
*
19+
* Unless required by applicable law or agreed to in writing, software
20+
* distributed under the License is distributed on an "AS IS" BASIS,
21+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
22+
* implied. See the License for the specific language governing
23+
* permissions and limitations under the License.
24+
*
25+
* \brief Input channel java 9 style cleanup.
26+
*/
27+
package com.quantcast.qfs.access;
28+
29+
final public class KfsOutputChannel extends KfsOutputChannelBase {
30+
31+
KfsOutputChannel(KfsAccessBase ka, int fd) {
32+
super(ka, fd);
33+
registerCleanup();
34+
}
35+
36+
private void registerCleanup() {
37+
KfsAccess.registerCleanup(this, state);
38+
}
39+
}

src/java/qfs-access/src/main/java/com/quantcast/qfs/access/KfsAccess.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,19 @@
2828

2929
import java.io.IOException;
3030

31-
final public class KfsAccess extends KfsAccessBase
32-
{
33-
public KfsAccess(String configFn) throws IOException
34-
{
31+
final public class KfsAccess extends KfsAccessBase {
32+
33+
public KfsAccess(String configFn) throws IOException {
3534
super(configFn);
3635
}
3736

3837
public KfsAccess(String metaServerHost,
39-
int metaServerPort) throws IOException
40-
{
38+
int metaServerPort) throws IOException {
4139
super(metaServerHost, metaServerPort);
4240
}
4341

4442
@Override
45-
protected void finalize() throws Throwable
46-
{
43+
protected void finalize() throws Throwable {
4744
try {
4845
kfs_destroy();
4946
} finally {

0 commit comments

Comments
 (0)