Skip to content

Commit 12f2bbb

Browse files
authored
Merge pull request #2 from googlielmo/bundle-0.3-hazelcast-all-3.11.1
Update to Hazelcast 3.11
2 parents 10f1bf4 + ae86e76 commit 12f2bbb

18 files changed

+1076
-67
lines changed

README.md

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,15 @@ This repository contains Hazelcast DynaCache feature for Liberty Profile.
1313
In Liberty WAS, you can use dynamic cache engine (which is the default) in order to cache your data.
1414
With this feature, you can use Hazelcast as cache provider.
1515

16+
Tested with Liberty 16.0.0.3.
17+
1618
# Requirements
1719

1820
- Maven
1921
- Download and extract [Liberty 16.0.0.3](https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/downloads/wlp/16.0.0.3/wlp-javaee7-16.0.0.3.zip)
2022

2123
# Creating Development Environment
2224

23-
- Clone `bundle` branch of the modified version of Hazelcast library:
24-
25-
```
26-
git clone -b bundle https://github.com/emre-aydin/hazelcast.git
27-
```
28-
29-
- Install the modified version of Hazelcast into local Maven repository. Execute the following in `hazelcast`
30-
project root directory:
31-
32-
```
33-
mvn clean install -DskipTests=true
34-
```
35-
3625
- Clone this GitHub repository:
3726

3827
```
@@ -46,7 +35,7 @@ project root directory:
4635
Install the `.esa` file by executing the following command:
4736
4837
```
49-
<liberty dir>/bin/featureManager install hazelcast-dynacache/hazelcast-dynacache/target/hazelcast-dynacache-0.2.esa
38+
<liberty dir>/bin/featureManager install hazelcast-dynacache/hazelcast-dynacache/target/hazelcast-dynacache-0.3.esa
5039
```
5140
5241
Use `hazelcast` as your cache provider name in your `cacheinstances.properties` file.
@@ -68,8 +57,7 @@ Enable Hazelcast DynaCache by adding the following snippet to your `server.xml`
6857
[Apply the iFix](http://www.ibm.com/support/knowledgecenter/SS7K4U_8.5.5/com.ibm.websphere.installation.nd.doc/ae/tins_install_fixes_dist.html)
6958
under `twas-ifix` directory to your WebSphere server and put the following files under `WAS_HOME/lib/ext`:
7059
71-
* hazelcast-3.8-BUNDLE.jar
72-
* hazelcast-client-3.8-BUNDLE.jar
73-
* hazelcast-dynacache-bundle-0.2.jar
60+
* hazelcast-all-3.11.jar
61+
* hazelcast-dynacache-bundle-0.3.jar
7462
7563
Use `com.hazelcast.ibm.dynacache.CacheProviderImpl` as your cache provider name in your `cacheinstances.properties` file.

hazelcast-dynacache-bundle/pom.xml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
~ Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.
2+
~ Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved.
33
~
44
~ Licensed under the Apache License, Version 2.0 (the "License");
55
~ you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@
2121
<parent>
2222
<groupId>com.hazelcast</groupId>
2323
<artifactId>hazelcast-dynacache-root</artifactId>
24-
<version>0.2</version>
24+
<version>0.3</version>
2525
</parent>
2626

2727
<artifactId>hazelcast-dynacache-bundle</artifactId>
@@ -31,7 +31,7 @@
3131
<dependencies>
3232
<dependency>
3333
<groupId>com.hazelcast</groupId>
34-
<artifactId>hazelcast-client</artifactId>
34+
<artifactId>hazelcast-all</artifactId>
3535
<version>${hazelcast.version}</version>
3636
</dependency>
3737
<dependency>
@@ -70,18 +70,13 @@
7070
<extensions>true</extensions>
7171
<configuration>
7272
<instructions>
73-
<Bundle-Activator>com.hazelcast.ibm.dynacache.Activator</Bundle-Activator>
73+
<Bundle-Activator>com.hazelcast.client.osgi.Activator</Bundle-Activator>
7474
<Export-Package>
75-
com.hazelcast.ibm.dynacache
75+
com.hazelcast.ibm.dynacache,
76+
com.hazelcast.client.osgi
7677
</Export-Package>
7778
<Import-Package>
78-
com.hazelcast.client;version="3.8.0.BUNDLE",
79-
com.hazelcast.client.osgi;version="3.8.0.BUNDLE",
80-
com.hazelcast.client.config;version="3.8.0.BUNDLE",
81-
com.hazelcast.client.impl;version="3.8.0.BUNDLE",
82-
com.hazelcast.config;version="3.8.0.BUNDLE",
83-
com.hazelcast.core;version="3.8.0.BUNDLE",
84-
com.hazelcast.map;version="3.8.0.BUNDLE",
79+
com.hazelcast.*;version="3.11.0",
8580
com.ibm.websphere.cache;version="1.0.0",
8681
com.ibm.wsspi.cache;version="1.1.0",
8782
org.osgi.framework;version="1.8.0",
@@ -91,7 +86,6 @@
9186
OSGI-INF/com.hazelcast.ibm.dynacache.CacheProviderImpl.xml
9287
</Service-Component>
9388
<Bundle-RequiredExecutionEnvironment>JavaSE-1.7</Bundle-RequiredExecutionEnvironment>
94-
<Application-Content>com.hazelcast.client;version="[3.8.0.BUNDLE,3.8.0.BUNDLE]"</Application-Content>
9589
</instructions>
9690
</configuration>
9791
</plugin>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.hazelcast.client.osgi;
18+
19+
import com.hazelcast.logging.ILogger;
20+
import com.hazelcast.logging.Logger;
21+
import org.osgi.framework.BundleActivator;
22+
import org.osgi.framework.BundleContext;
23+
24+
import java.lang.reflect.Method;
25+
26+
/**
27+
* Hazelcast OSGi bundle activator.
28+
*
29+
* @see org.osgi.framework.BundleActivator
30+
*/
31+
public class Activator
32+
implements BundleActivator {
33+
34+
private static final ILogger LOGGER = Logger.getLogger(Activator.class);
35+
36+
// Defined as `volatile` since Javadoc of `BundleActivator` says that
37+
// `The Framework must not concurrently call a BundleActivator object`
38+
// and also it is marked as `@NotThreadSafe`.
39+
// So it can be called from different threads but cannot be called concurrently.
40+
private volatile HazelcastClientInternalOSGiService hazelcastClientOSGiService;
41+
42+
@Override
43+
public void start(BundleContext context)
44+
throws Exception {
45+
// Try to start javax.scripting - JSR 223
46+
activateJavaxScripting(context);
47+
48+
assert hazelcastClientOSGiService == null : "Hazelcast OSGI service should be null while starting!";
49+
50+
// Create a new Hazelcast OSGI service with given bundle and its context
51+
hazelcastClientOSGiService = new HazelcastClientOSGiServiceImpl(context.getBundle());
52+
53+
// Activate new created Hazelcast OSGI service
54+
hazelcastClientOSGiService.activate();
55+
56+
LOGGER.finest("hazelcast-dynacache bundle started");
57+
}
58+
59+
@Override
60+
public void stop(BundleContext context)
61+
throws Exception {
62+
assert hazelcastClientOSGiService != null : "Hazelcast OSGI service should not be null while stopping!";
63+
64+
hazelcastClientOSGiService.deactivate();
65+
hazelcastClientOSGiService = null;
66+
67+
LOGGER.finest("hazelcast-dynacache bundle stopped");
68+
}
69+
70+
private void activateJavaxScripting(BundleContext context)
71+
throws Exception {
72+
if (isJavaxScriptingAvailable()) {
73+
Class<?> clazz = context.getBundle().loadClass("com.hazelcast.osgi.impl.ScriptEngineActivator");
74+
Method register = clazz.getDeclaredMethod("registerOsgiScriptEngineManager", BundleContext.class);
75+
register.setAccessible(true);
76+
register.invoke(clazz, context);
77+
} else {
78+
LOGGER.warning("Hazelcast: javax.scripting is not available, scripts from Management Center cannot be executed!");
79+
}
80+
}
81+
82+
static boolean isJavaxScriptingAvailable() {
83+
try {
84+
Class.forName("javax.script.ScriptEngineManager");
85+
return true;
86+
} catch (ClassNotFoundException e) {
87+
return false;
88+
}
89+
}
90+
91+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.hazelcast.client.osgi;
18+
19+
import com.hazelcast.instance.BuildInfoProvider;
20+
import com.hazelcast.osgi.HazelcastOSGiService;
21+
22+
/**
23+
* Contract point for internal Hazelcast services on top of OSGI.
24+
*
25+
* @see HazelcastOSGiService
26+
*/
27+
public interface HazelcastClientInternalOSGiService
28+
extends HazelcastClientOSGiService {
29+
30+
/**
31+
* Default id for {@link HazelcastClientInternalOSGiService} instance
32+
*/
33+
String DEFAULT_ID =
34+
BuildInfoProvider.getBuildInfo().getVersion()
35+
+ "#"
36+
+ (BuildInfoProvider.getBuildInfo().isEnterprise() ? "EE" : "OSS");
37+
38+
/**
39+
* Default group name to be used when grouping is not disabled with
40+
* {@link HazelcastOSGiService#HAZELCAST_OSGI_GROUPING_DISABLED}.
41+
*/
42+
String DEFAULT_GROUP_NAME = DEFAULT_ID;
43+
44+
/**
45+
* Returns the state of the service about if it is active or not.
46+
*
47+
* @return <code>true</code> if the service is active, otherwise <code>false</code>
48+
*/
49+
boolean isActive();
50+
51+
/**
52+
* Activates the service.
53+
*/
54+
void activate();
55+
56+
/**
57+
* Deactivates the service.
58+
*/
59+
void deactivate();
60+
61+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.hazelcast.client.osgi;
18+
19+
import com.hazelcast.client.config.ClientConfig;
20+
import com.hazelcast.osgi.HazelcastOSGiInstance;
21+
import org.osgi.framework.Bundle;
22+
23+
import java.util.Set;
24+
25+
/**
26+
* Contract point for Hazelcast services on top of OSGI.
27+
*/
28+
public interface HazelcastClientOSGiService {
29+
30+
/**
31+
* System property for starting a default Hazelcast instance per Hazelcast OSGI bundle.
32+
*/
33+
String HAZELCAST_OSGI_START = "hazelcast.osgi.start";
34+
35+
/**
36+
* System property for disabling the behaviour that registers created Hazelcast instances as OSGI service.
37+
*/
38+
String HAZELCAST_OSGI_REGISTER_DISABLED = "hazelcast.osgi.register.disabled";
39+
40+
/**
41+
* System property for disabling the behaviour that gives different group name
42+
* to each Hazelcast bundle.
43+
*/
44+
String HAZELCAST_OSGI_GROUPING_DISABLED = "hazelcast.osgi.grouping.disabled";
45+
46+
/**
47+
* Gets the id of service.
48+
*
49+
* @return the id of service
50+
*/
51+
String getId();
52+
53+
/**
54+
* Gets the owner {@link Bundle} of this instance.
55+
*
56+
* @return the owner {@link Bundle} of this instance
57+
*/
58+
Bundle getOwnerBundle();
59+
60+
/**
61+
* Gets the default {@link HazelcastOSGiClientInstance}.
62+
*
63+
* @return the default {@link HazelcastOSGiClientInstance}
64+
*/
65+
HazelcastOSGiClientInstance getDefaultHazelcastInstance();
66+
67+
/**
68+
* Creates a new {@link HazelcastOSGiClientInstance}
69+
* on the owner bundle with specified configuration.
70+
*
71+
* @param config Configuration for the new {@link HazelcastOSGiClientInstance} (member)
72+
* @return the new {@link HazelcastOSGiClientInstance}
73+
*/
74+
HazelcastOSGiClientInstance newHazelcastInstance(ClientConfig config);
75+
76+
/**
77+
* Creates a new {@link HazelcastOSGiClientInstance}
78+
* on the owner bundle with default configuration.
79+
*
80+
* @return the new {@link HazelcastOSGiClientInstance}
81+
*/
82+
HazelcastOSGiClientInstance newHazelcastInstance();
83+
84+
/**
85+
* Gets an existing {@link HazelcastOSGiInstance} with its <code>instanceName</code>.
86+
*
87+
* @param instanceName Name of the {@link HazelcastOSGiClientInstance} (member)
88+
* @return an existing {@link HazelcastOSGiClientInstance}
89+
*/
90+
HazelcastOSGiClientInstance getHazelcastInstanceByName(String instanceName);
91+
92+
/**
93+
* Gets all active/running {@link HazelcastOSGiClientInstance}s on the owner bundle.
94+
*
95+
* @return all active/running {@link HazelcastOSGiClientInstance}s on the owner bundle
96+
*/
97+
Set<HazelcastOSGiClientInstance> getAllHazelcastInstances();
98+
99+
/**
100+
* Shuts down the given {@link HazelcastOSGiInstance} on the owner bundle.
101+
*
102+
* @param instance the {@link HazelcastOSGiClientInstance} to shutdown
103+
*/
104+
void shutdownHazelcastInstance(HazelcastOSGiClientInstance instance);
105+
106+
/**
107+
* Shuts down all running {@link HazelcastOSGiClientInstance}s on the owner bundle.
108+
*/
109+
void shutdownAll();
110+
111+
}

0 commit comments

Comments
 (0)