Author: [email protected] Date: Mon Aug 8 10:22:19 2011 New Revision: 1275 Log:
Added: sandbox/ivol/cassandra-example/ sandbox/ivol/cassandra-example/pom.xml sandbox/ivol/cassandra-example/src/ sandbox/ivol/cassandra-example/src/main/ sandbox/ivol/cassandra-example/src/main/java/ sandbox/ivol/cassandra-example/src/main/java/org/ sandbox/ivol/cassandra-example/src/main/java/org/amdatu/ sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/ sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/ sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/ sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/Profile.java sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/ProfileStore.java sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/osgi/ sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/osgi/Activator.java sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/service/ sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/service/ProfileColumnFamilyProviderImpl.java sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/service/ProfileImpl.java sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/service/ProfileStoreImpl.java Added: sandbox/ivol/cassandra-example/pom.xml ============================================================================== --- (empty file) +++ sandbox/ivol/cassandra-example/pom.xml Mon Aug 8 10:22:19 2011 @@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2010, 2011 The Amdatu Foundation + + Licensed 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.verning permissions and limitations + under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.amdatu.cassandra</groupId> + <artifactId>org.amdatu.cassandra</artifactId> + <version>0.2.1-SNAPSHOT</version> + </parent> + <artifactId>org.amdatu.cassandra.example.profile</artifactId> + <packaging>bundle</packaging> + <name>Amdatu Cassandra - Profile Example</name> + <description>Provides an example implementation of a profile store</description> + + <properties> + <amdatu.auth.version>0.2.0</amdatu.auth.version> + </properties> + + <dependencies> + <dependency> + <groupId>org.amdatu.cassandra</groupId> + <artifactId>org.amdatu.cassandra.listener</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.cassandra</groupId> + <artifactId>org.amdatu.cassandra.application</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.cassandra</groupId> + <artifactId>org.amdatu.cassandra.persistencemanager</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.core</groupId> + <artifactId>org.amdatu.core.tenant</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.cassandra</groupId> + <artifactId>org.amdatu.cassandra.test.unit</artifactId> + <type>jar</type> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <artifactId>maven-source-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <configuration> + <instructions> + <Bundle-Activator>org.amdatu.cassandra.example.profile.osgi.Activator</Bundle-Activator> + <Bundle-SymbolicName>org.amdatu.cassandra.example.profile</Bundle-SymbolicName> + <Embed-Dependency>*;scope=compile</Embed-Dependency> + <Embed-Transitive>true</Embed-Transitive> + <Import-Package> + org.amdatu.cassandra.application;version="[1.0,2.0)", + org.amdatu.cassandra.listener;version="[1.0,2.0)", + org.amdatu.cassandra.persistencemanager;version="[1.0,2.0)", + me.prettyprint.hector.api.beans;version="[1.0,2.0)", + * + </Import-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> +</project> Added: sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/Profile.java ============================================================================== --- (empty file) +++ sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/Profile.java Mon Aug 8 10:22:19 2011 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2011 The Amdatu Foundation + * + * Licensed 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.amdatu.cassandra.example.profile; + +import java.util.Map; + +public interface Profile { + String getId(); + + void setId(String id); + + String getName(); + + void setName(String name); + + String getEmailAddress(); + + void setEmailAddress(String emailAddress); + + Map<String, String> getProperties(); + + void setProperties(Map<String, String> properties); +} Added: sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/ProfileStore.java ============================================================================== --- (empty file) +++ sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/ProfileStore.java Mon Aug 8 10:22:19 2011 @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2011 The Amdatu Foundation + * + * Licensed 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.amdatu.cassandra.example.profile; + +public interface ProfileStore { + +} \ No newline at end of file Added: sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/osgi/Activator.java ============================================================================== --- (empty file) +++ sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/osgi/Activator.java Mon Aug 8 10:22:19 2011 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2010, 2011 The Amdatu Foundation + * + * Licensed 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.amdatu.cassandra.example.profile.osgi; + +import org.amdatu.cassandra.example.profile.ProfileStore; +import org.amdatu.cassandra.example.profile.service.ProfileColumnFamilyProviderImpl; +import org.amdatu.cassandra.example.profile.service.ProfileStoreImpl; +import org.amdatu.cassandra.listener.ColumnFamilyAvailable; +import org.amdatu.cassandra.listener.ColumnFamilyProvider; +import org.amdatu.cassandra.persistencemanager.CassandraPersistenceManager; +import org.apache.felix.dm.DependencyActivatorBase; +import org.apache.felix.dm.DependencyManager; +import org.osgi.framework.BundleContext; +import org.osgi.service.log.LogService; + +/** + * This class implements the OSGi Activator of this bundle. It is responsible for the registration of + * all service components contained by this bundle. + */ +public class Activator extends DependencyActivatorBase { + + public void init(final BundleContext context, final DependencyManager manager) { + // To append a column family to Cassandra, we need to register a service implementing + // the ColumnFamilyProvider interface. The implementation defines the properties of + // that ColumnFamily, like the type (Super or Standard) and the keyspace(s) the ColumnFamily + // should be added too. + manager.add(createComponent() + .setInterface(new String[]{ColumnFamilyProvider.class.getName()}, null) + .setImplementation(ProfileColumnFamilyProviderImpl.class)); + + // Create and register the profile service. The profile service will store its data in + // the Profile ColumnFamily, defined by the ProfileColumnFamilyProviderImpl service component + // registered above. This ColumnFamily defines that this ColumnFamily should only be added + // the Default keyspace. For that reason, it needs to use the Cassandra Persistence Manager + // for that particular keyspace (Cassandra Persistence Managers are available for each keyspace). + // Therefore we define a keyspace filter which we will use to define a service dependency + // on this specific persistence manager. + String keyspaceFilter = "(" + CassandraPersistenceManager.KEYSPACE_AWARE_KEY + "=" + + CassandraPersistenceManager.DEFAULT_KEYSPACE + ")"; + + // The profile service stores its data in the Profile ColumnFamily. That means that this + // service can only do its work if that ColumnFamily is available. The ColumnFamily is created + // asynchronously by registration of the ColumnFamilyProvider service above. To ensure + // that this service does not run before this ColumnFamily is available, we can define + // a service dependency with the ColumnFamilyAvailable service, provided with a filter + // for our specific Profile ColumnFamily. + String profileCFFilter = "(&" + keyspaceFilter + "(" + ColumnFamilyAvailable.FILTER_NAME + + "=" + ProfileColumnFamilyProviderImpl.CF_PROFILE + "))"; + + // Create and register the profile service + manager.add( + createComponent() + .setImplementation(ProfileStoreImpl.class) + .setInterface(ProfileStore.class.getName(), null) + .add(createServiceDependency().setService(LogService.class).setRequired(true)) + .add(createServiceDependency().setService(CassandraPersistenceManager.class, keyspaceFilter).setRequired(true)) + .add(createServiceDependency().setService(ColumnFamilyAvailable.class, profileCFFilter).setRequired(true))); + } + + @Override + public void destroy(final BundleContext context, final DependencyManager manager) throws Exception { + } +} + + Added: sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/service/ProfileColumnFamilyProviderImpl.java ============================================================================== --- (empty file) +++ sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/service/ProfileColumnFamilyProviderImpl.java Mon Aug 8 10:22:19 2011 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2010, 2011 The Amdatu Foundation + * + * Licensed 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.amdatu.cassandra.example.profile.service; + +import org.amdatu.cassandra.listener.ColumnFamilyDefinition; +import org.amdatu.cassandra.listener.ColumnFamilyDefinition.ColumnType; +import org.amdatu.cassandra.listener.ColumnFamilyDefinition.CompareType; +import org.amdatu.cassandra.listener.ColumnFamilyProvider; +import org.amdatu.cassandra.persistencemanager.CassandraPersistenceManager; + +/** + * This service provides the ColumnFamily 'Profile'. + * + * @author ivol + */ +public class ProfileColumnFamilyProviderImpl implements ColumnFamilyProvider { + /** + * Name of the ColumnFamily that stores the profiles. + */ + public static final String CF_PROFILE = "ExampleProfile"; + + // Column families of this ColumnFamily. Note that we will store all values as + // String, even though the properties attribute is not of type String but of + // type Map<String, String>. The advantage of storing all columns with the same + // data type is that it is much easier to retrieve all columns at once + public static final String C_NAME = "name"; + public static final String C_EMAIL = "email"; + public static final String C_PROPERTIES = "properties"; + + public ColumnFamilyDefinition[] getColumnFamilies() { + return new ColumnFamilyDefinition[] { + new ColumnFamilyDefinition( + // Name of the ColumnFamily + CF_PROFILE, + + // The keyspaces to add the ColumnFamily to. May be null, in which case the + // ColumnFamily is appended to all keyspaces (including keyspaces created later on). + // We append this ColumnFamily only to the Default keyspace, which is always available. + new String[] {CassandraPersistenceManager.DEFAULT_KEYSPACE}, + + // The type of the ColumnFamily, may be SUPER or STANDARD. We define STANDARD. + ColumnType.STANDARD, + + // The comparator type for its columns + CompareType.BYTESTYPE, + + // Since this is a STANDARD ColumnFamily, we should not provide a comparator for + // super columns, as it has none. + null)}; + } +} \ No newline at end of file Added: sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/service/ProfileImpl.java ============================================================================== --- (empty file) +++ sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/service/ProfileImpl.java Mon Aug 8 10:22:19 2011 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2010, 2011 The Amdatu Foundation + * + * Licensed 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.amdatu.cassandra.example.profile.service; + +import java.util.Map; + +/** + * This class implements a bean holding all properties of a Profile. + */ +public class ProfileImpl { + private String m_id; + private String m_name; + private String m_emailAddress; + private Map<String, String> m_properties; + + public String getId() { + return m_id; + } + + public void setId(String id) { + m_id = id; + } + + public String getName() { + return m_name; + } + + public void setName(String name) { + m_name = name; + } + + public String getEmailAddress() { + return m_emailAddress; + } + + public void setEmailAddress(String emailAddress) { + m_emailAddress = emailAddress; + } + + public Map<String, String> getProperties() { + return m_properties; + } + + public void setProperties(Map<String, String> properties) { + m_properties = properties; + } +} Added: sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/service/ProfileStoreImpl.java ============================================================================== --- (empty file) +++ sandbox/ivol/cassandra-example/src/main/java/org/amdatu/cassandra/example/profile/service/ProfileStoreImpl.java Mon Aug 8 10:22:19 2011 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2010, 2011 The Amdatu Foundation + * + * Licensed 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.amdatu.cassandra.example.profile.service; + +import static org.amdatu.cassandra.example.profile.service.ProfileColumnFamilyProviderImpl.CF_PROFILE; +import static org.amdatu.cassandra.example.profile.service.ProfileColumnFamilyProviderImpl.C_EMAIL; +import static org.amdatu.cassandra.example.profile.service.ProfileColumnFamilyProviderImpl.C_NAME; +import static org.amdatu.cassandra.example.profile.service.ProfileColumnFamilyProviderImpl.C_PROPERTIES; + +import org.amdatu.cassandra.example.profile.Profile; +import org.amdatu.cassandra.example.profile.ProfileStore; +import org.amdatu.cassandra.persistencemanager.CassandraPersistenceManager; + +public class ProfileStoreImpl implements ProfileStore { + // Service dependencies + private volatile CassandraPersistenceManager m_pm; + + public Profile getProfile(String id) { + m_pm.getColumns(CF_PROFILE, id, String.class); + } + + public void saveProfile(Profile profile) { + m_pm.setValue(CF_PROFILE, profile.getId(), null, C_NAME, profile.getName()); + m_pm.setValue(CF_PROFILE, profile.getId(), null, C_EMAIL, profile.getEmailAddress()); + m_pm.setValue(CF_PROFILE, profile.getId(), null, C_PROPERTIES, profile.getProperties()); + } + + public void deleteProfile(Profile profile) { + m_pm.deleteRow(CF_PROFILE, profile.getId()); + } +} \ No newline at end of file _______________________________________________ Amdatu-commits mailing list [email protected] http://lists.amdatu.org/mailman/listinfo/amdatu-commits
