You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/02/05 22:28:04 UTC
[10/90] [partial] Change package namespace to org.apache.usergrid
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c2acbe4/stack/core/src/main/java/org/usergrid/persistence/cassandra/Setup.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/cassandra/Setup.java b/stack/core/src/main/java/org/usergrid/persistence/cassandra/Setup.java
deleted file mode 100644
index 9c73648..0000000
--- a/stack/core/src/main/java/org/usergrid/persistence/cassandra/Setup.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * 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.usergrid.persistence.cassandra;
-
-
-import java.util.UUID;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.usergrid.mq.cassandra.QueuesCF;
-import org.usergrid.persistence.entities.Application;
-
-import me.prettyprint.hector.api.ddl.ComparatorType;
-
-import static me.prettyprint.hector.api.factory.HFactory.createColumnFamilyDefinition;
-import static org.usergrid.persistence.cassandra.CassandraPersistenceUtils.getCfDefs;
-import static org.usergrid.persistence.cassandra.CassandraService.APPLICATIONS_CF;
-import static org.usergrid.persistence.cassandra.CassandraService.DEFAULT_APPLICATION;
-import static org.usergrid.persistence.cassandra.CassandraService.DEFAULT_APPLICATION_ID;
-import static org.usergrid.persistence.cassandra.CassandraService.DEFAULT_ORGANIZATION;
-import static org.usergrid.persistence.cassandra.CassandraService.MANAGEMENT_APPLICATION;
-import static org.usergrid.persistence.cassandra.CassandraService.MANAGEMENT_APPLICATION_ID;
-import static org.usergrid.persistence.cassandra.CassandraService.PRINCIPAL_TOKEN_CF;
-import static org.usergrid.persistence.cassandra.CassandraService.PROPERTIES_CF;
-import static org.usergrid.persistence.cassandra.CassandraService.STATIC_APPLICATION_KEYSPACE;
-import static org.usergrid.persistence.cassandra.CassandraService.SYSTEM_KEYSPACE;
-import static org.usergrid.persistence.cassandra.CassandraService.TOKENS_CF;
-import static org.usergrid.persistence.cassandra.CassandraService.USE_VIRTUAL_KEYSPACES;
-import static org.usergrid.persistence.cassandra.CassandraService.keyspaceForApplication;
-
-
-/**
- * Cassandra-specific setup utilities.
- *
- * @author edanuff
- */
-public class Setup {
-
- private static final Logger logger = LoggerFactory.getLogger( Setup.class );
-
- private final org.usergrid.persistence.EntityManagerFactory emf;
- private final CassandraService cass;
-
-
- /**
- * Instantiates a new setup object.
- *
- * @param emf the emf
- */
- public Setup( EntityManagerFactoryImpl emf, CassandraService cass ) {
- this.emf = emf;
- this.cass = cass;
- }
-
-
- /**
- * Initialize.
- *
- * @throws Exception the exception
- */
- public synchronized void setup() throws Exception {
- init();
-
- setupSystemKeyspace();
-
- setupStaticKeyspace();
-
- createDefaultApplications();
- }
-
-
- public void init() throws Exception {
- cass.init();
- }
-
-
- public void createDefaultApplications() throws Exception {
- // TODO unique check?
- ( ( EntityManagerFactoryImpl ) emf )
- .initializeApplication( DEFAULT_ORGANIZATION, DEFAULT_APPLICATION_ID, DEFAULT_APPLICATION, null );
-
- ( ( EntityManagerFactoryImpl ) emf )
- .initializeApplication( DEFAULT_ORGANIZATION, MANAGEMENT_APPLICATION_ID, MANAGEMENT_APPLICATION, null );
- }
-
-
- /**
- * Initialize system keyspace.
- *
- * @throws Exception the exception
- */
- public void setupSystemKeyspace() throws Exception {
-
- logger.info( "Initialize system keyspace" );
-
- cass.createColumnFamily( SYSTEM_KEYSPACE,
- createColumnFamilyDefinition( SYSTEM_KEYSPACE, APPLICATIONS_CF, ComparatorType.BYTESTYPE ) );
-
- cass.createColumnFamily( SYSTEM_KEYSPACE,
- createColumnFamilyDefinition( SYSTEM_KEYSPACE, PROPERTIES_CF, ComparatorType.BYTESTYPE ) );
-
- cass.createColumnFamily( SYSTEM_KEYSPACE,
- createColumnFamilyDefinition( SYSTEM_KEYSPACE, TOKENS_CF, ComparatorType.BYTESTYPE ) );
-
- cass.createColumnFamily( SYSTEM_KEYSPACE,
- createColumnFamilyDefinition( SYSTEM_KEYSPACE, PRINCIPAL_TOKEN_CF, ComparatorType.UUIDTYPE ) );
-
- logger.info( "System keyspace initialized" );
- }
-
-
- /**
- * Initialize application keyspace.
- *
- * @param applicationId the application id
- * @param applicationName the application name
- *
- * @throws Exception the exception
- */
- public void setupApplicationKeyspace( final UUID applicationId, String applicationName ) throws Exception {
-
- if ( !USE_VIRTUAL_KEYSPACES ) {
- String app_keyspace = keyspaceForApplication( applicationId );
-
- logger.info( "Creating application keyspace " + app_keyspace + " for " + applicationName + " application" );
-
- cass.createColumnFamily( app_keyspace,
- createColumnFamilyDefinition( SYSTEM_KEYSPACE, APPLICATIONS_CF, ComparatorType.BYTESTYPE ) );
-
- cass.createColumnFamilies( app_keyspace, getCfDefs( ApplicationCF.class, app_keyspace ) );
- cass.createColumnFamilies( app_keyspace, getCfDefs( QueuesCF.class, app_keyspace ) );
- }
- }
-
-
- public void setupStaticKeyspace() throws Exception {
-
- if ( USE_VIRTUAL_KEYSPACES ) {
-
- logger.info( "Creating static application keyspace " + STATIC_APPLICATION_KEYSPACE );
-
- cass.createColumnFamily( STATIC_APPLICATION_KEYSPACE,
- createColumnFamilyDefinition( STATIC_APPLICATION_KEYSPACE, APPLICATIONS_CF,
- ComparatorType.BYTESTYPE ) );
-
- cass.createColumnFamilies( STATIC_APPLICATION_KEYSPACE,
- getCfDefs( ApplicationCF.class, STATIC_APPLICATION_KEYSPACE ) );
- cass.createColumnFamilies( STATIC_APPLICATION_KEYSPACE,
- getCfDefs( QueuesCF.class, STATIC_APPLICATION_KEYSPACE ) );
- }
- }
-
-
- public boolean keyspacesExist() {
- return cass.checkKeyspacesExist();
- }
-
-
- public static void logCFPermissions() {
- System.out.println( SYSTEM_KEYSPACE + "." + APPLICATIONS_CF + ".<rw>=usergrid" );
- System.out.println( SYSTEM_KEYSPACE + "." + PROPERTIES_CF + ".<rw>=usergrid" );
- for ( CFEnum cf : ApplicationCF.values() ) {
- System.out.println( STATIC_APPLICATION_KEYSPACE + "." + cf + ".<rw>=usergrid" );
- }
- for ( CFEnum cf : QueuesCF.values() ) {
- System.out.println( STATIC_APPLICATION_KEYSPACE + "." + cf + ".<rw>=usergrid" );
- }
- }
-
-
- /** @return staticly constructed reference to the management application */
- public static Application getManagementApp() {
- return SystemDefaults.managementApp;
- }
-
-
- /** @return statically constructed reference to the default application */
- public static Application getDefaultApp() {
- return SystemDefaults.defaultApp;
- }
-
-
- static class SystemDefaults {
- private static final Application managementApp = new Application( MANAGEMENT_APPLICATION_ID );
- private static final Application defaultApp = new Application( DEFAULT_APPLICATION_ID );
-
-
- static {
- managementApp.setName( MANAGEMENT_APPLICATION );
- defaultApp.setName( DEFAULT_APPLICATION );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c2acbe4/stack/core/src/main/java/org/usergrid/persistence/cassandra/SimpleIndexBucketLocatorImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/cassandra/SimpleIndexBucketLocatorImpl.java b/stack/core/src/main/java/org/usergrid/persistence/cassandra/SimpleIndexBucketLocatorImpl.java
deleted file mode 100644
index c8d105c..0000000
--- a/stack/core/src/main/java/org/usergrid/persistence/cassandra/SimpleIndexBucketLocatorImpl.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * 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.usergrid.persistence.cassandra;
-
-
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.UUID;
-
-import org.usergrid.persistence.IndexBucketLocator;
-
-import static org.apache.commons.codec.digest.DigestUtils.md5;
-import static org.usergrid.utils.ConversionUtils.bytes;
-
-
-/**
- * Simple implementation that does static hashing across 100 rows. Future implementations should be smarter and create
- * new tokens as required when buckets become too large for an entity property within an application for the given index
- * type.
- *
- * @author tnine
- */
-public class SimpleIndexBucketLocatorImpl implements IndexBucketLocator {
-
- public static final BigInteger MINIMUM = BigInteger.ZERO;
- public static final BigInteger MAXIMUM = new BigInteger( "" + 2 ).pow( 127 );
-
- private final List<BigInteger> buckets = new ArrayList<BigInteger>( 100 );
- private final List<String> bucketsString = new ArrayList<String>( 100 );
- private final int size;
-
-
- /** Create a bucket locator with the specified size */
- public SimpleIndexBucketLocatorImpl( int size ) {
- for ( int i = 0; i < size; i++ ) {
- BigInteger integer = initialToken( size, i );
- buckets.add( integer );
- bucketsString.add( String.format( "%039d", integer ) );
- }
-
- this.size = size;
- }
-
-
- /** Base constructor that creates a ring of 100 tokens */
- public SimpleIndexBucketLocatorImpl() {
- this( 100 );
- }
-
-
- /** Get a token */
- private static BigInteger initialToken( int size, int position ) {
- BigInteger decValue = MINIMUM;
- if ( position != 0 ) {
- decValue = MAXIMUM.divide( new BigInteger( "" + size ) ).multiply( new BigInteger( "" + position ) )
- .subtract( BigInteger.ONE );
- }
- return decValue;
- }
-
-
- /** Get the next token in the ring for this big int. */
- private String getClosestToken( UUID entityId ) {
- BigInteger location = new BigInteger( md5( bytes( entityId ) ) );
- location = location.abs();
-
- int index = Collections.binarySearch( buckets, location );
-
- if ( index < 0 ) {
- index = ( index + 1 ) * -1;
- }
-
- // mod if we need to wrap
- index = index % size;
-
- return bucketsString.get( index );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.usergrid.persistence.IndexBucketLocator#getBucket(java.util.UUID,
- * org.usergrid.persistence.IndexBucketLocator.IndexType, java.util.UUID,
- * java.lang.String[])
- */
- @Override
- public String getBucket( UUID applicationId, IndexType type, UUID entityId, String... components ) {
- return getClosestToken( entityId );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.usergrid.persistence.IndexBucketLocator#getBuckets(java.util.UUID,
- * org.usergrid.persistence.IndexBucketLocator.IndexType,
- * java.lang.String[])
- */
- @Override
- public List<String> getBuckets( UUID applicationId, IndexType type, String... components ) {
- return bucketsString;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c2acbe4/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/ConnectedIndexScanner.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/ConnectedIndexScanner.java b/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/ConnectedIndexScanner.java
deleted file mode 100644
index 265dc4d..0000000
--- a/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/ConnectedIndexScanner.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * 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.usergrid.persistence.cassandra.index;
-
-
-import java.nio.ByteBuffer;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.UUID;
-
-import org.springframework.util.Assert;
-import org.usergrid.persistence.cassandra.CassandraService;
-
-import com.yammer.metrics.annotation.Metered;
-
-import me.prettyprint.hector.api.beans.HColumn;
-
-import static org.usergrid.persistence.cassandra.ApplicationCF.ENTITY_COMPOSITE_DICTIONARIES;
-import static org.usergrid.persistence.cassandra.CassandraPersistenceUtils.key;
-
-
-/** @author tnine */
-public class ConnectedIndexScanner implements IndexScanner {
-
- private final CassandraService cass;
- private final UUID applicationId;
- private final boolean reversed;
- private final int pageSize;
- private final String dictionaryType;
- private final UUID entityId;
- private final Iterator<String> connectionTypes;
-
- /** Pointer to our next start read */
- private ByteBuffer start;
-
- /** Set to the original value to start scanning from */
- private ByteBuffer scanStart;
-
- /** Iterator for our results from the last page load */
- private LinkedHashSet<HColumn<ByteBuffer, ByteBuffer>> lastResults;
-
- /** True if our last load loaded a full page size. */
- private boolean hasMore = true;
-
- private String currentConnectionType;
-
-
- public ConnectedIndexScanner( CassandraService cass, String dictionaryType, UUID applicationId, UUID entityId,
- Iterator<String> connectionTypes, ByteBuffer start, boolean reversed, int pageSize ) {
-
- Assert.notNull( entityId, "Entity id for row key construction must be specified when searching graph indexes" );
- // create our start and end ranges
- this.scanStart = start;
- this.cass = cass;
- this.applicationId = applicationId;
- this.entityId = entityId;
- this.start = scanStart;
- this.reversed = reversed;
- this.pageSize = pageSize;
- this.dictionaryType = dictionaryType;
- this.connectionTypes = connectionTypes;
-
-
- if ( connectionTypes.hasNext() ) {
- currentConnectionType = connectionTypes.next();
- }
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.usergrid.persistence.cassandra.index.IndexScanner#reset()
- */
- @Override
- public void reset() {
- hasMore = true;
- start = scanStart;
- }
-
-
- /**
- * Search the collection index using all the buckets for the given collection. Load the next page. Return false if
- * nothing was loaded, true otherwise
- */
-
- public boolean load() throws Exception {
-
- // nothing left to load
- if ( !hasMore ) {
- return false;
- }
-
-
- lastResults = new LinkedHashSet<HColumn<ByteBuffer, ByteBuffer>>();
-
- //go through each connection type until we exhaust the result sets
- while ( currentConnectionType != null ) {
-
- //only load a delta size to get this next page
- int selectSize = pageSize + 1 - lastResults.size();
-
- Object key = key( entityId, dictionaryType, currentConnectionType );
-
-
- List<HColumn<ByteBuffer, ByteBuffer>> results =
- cass.getColumns( cass.getApplicationKeyspace( applicationId ), ENTITY_COMPOSITE_DICTIONARIES, key,
- start, null, selectSize, reversed );
-
- lastResults.addAll( results );
-
- // we loaded a full page, there might be more
- if ( results.size() == selectSize ) {
- hasMore = true;
-
- // set the bytebuffer for the next pass
- start = results.get( results.size() - 1 ).getName();
-
- lastResults.remove( lastResults.size() - 1 );
-
- //we've loaded a full page
- break;
- }
- else {
-
- //we're done, there's no more connection types and we've loaded all cols for this type.
- if ( !connectionTypes.hasNext() ) {
- hasMore = false;
- currentConnectionType = null;
- break;
- }
-
- //we have more connection types, but we've reached the end of this type,
- // keep going in the loop to load the next page
-
- currentConnectionType = connectionTypes.next();
- }
- }
-
-
- return lastResults != null && lastResults.size() > 0;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Iterable#iterator()
- */
- @Override
- public Iterator<Set<HColumn<ByteBuffer, ByteBuffer>>> iterator() {
- return this;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#hasNext()
- */
- @Override
- public boolean hasNext() {
-
- // We've either 1) paged everything we should and have 1 left from our
- // "next page" pointer
- // Our currently buffered results don't exist or don't have a next. Try to
- // load them again if they're less than the page size
- if ( lastResults == null && hasMore ) {
- try {
- return load();
- }
- catch ( Exception e ) {
- throw new RuntimeException( "Error loading next page of indexbucket scanner", e );
- }
- }
-
- return false;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#next()
- */
- @Override
- @Metered(group = "core", name = "IndexBucketScanner_load")
- public Set<HColumn<ByteBuffer, ByteBuffer>> next() {
- Set<HColumn<ByteBuffer, ByteBuffer>> returnVal = lastResults;
-
- lastResults = null;
-
- return returnVal;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#remove()
- */
- @Override
- public void remove() {
- throw new UnsupportedOperationException( "You can't remove from a result set, only advance" );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.usergrid.persistence.cassandra.index.IndexScanner#getPageSize()
- */
- @Override
- public int getPageSize() {
- return pageSize;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c2acbe4/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/IndexBucketScanner.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/IndexBucketScanner.java b/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/IndexBucketScanner.java
deleted file mode 100644
index 1a0776a..0000000
--- a/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/IndexBucketScanner.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * 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.usergrid.persistence.cassandra.index;
-
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NavigableSet;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.UUID;
-
-import org.usergrid.persistence.IndexBucketLocator;
-import org.usergrid.persistence.IndexBucketLocator.IndexType;
-import org.usergrid.persistence.cassandra.ApplicationCF;
-import org.usergrid.persistence.cassandra.CassandraService;
-
-import com.yammer.metrics.annotation.Metered;
-
-import me.prettyprint.hector.api.beans.HColumn;
-
-import static org.usergrid.persistence.cassandra.CassandraPersistenceUtils.key;
-
-
-/**
- * A simple class to make working with index buckets easier. Scans all buckets and merges the results into a single
- * column list to allow easy backwards compatibility with existing code
- *
- * @author tnine
- */
-public class IndexBucketScanner implements IndexScanner {
-
- private final CassandraService cass;
- private final IndexBucketLocator indexBucketLocator;
- private final UUID applicationId;
- private final Object keyPrefix;
- private final ApplicationCF columnFamily;
- private final Object finish;
- private final boolean reversed;
- private final int pageSize;
- private final String[] indexPath;
- private final IndexType indexType;
-
- /** Pointer to our next start read */
- private Object start;
-
- /** Set to the original value to start scanning from */
- private Object scanStart;
-
- /** Iterator for our results from the last page load */
- private TreeSet<HColumn<ByteBuffer, ByteBuffer>> lastResults;
-
- /** True if our last load loaded a full page size. */
- private boolean hasMore = true;
-
-
- public IndexBucketScanner( CassandraService cass, IndexBucketLocator locator, ApplicationCF columnFamily,
- UUID applicationId, IndexType indexType, Object keyPrefix, Object start, Object finish,
- boolean reversed, int pageSize, String... indexPath ) {
- this.cass = cass;
- this.indexBucketLocator = locator;
- this.applicationId = applicationId;
- this.keyPrefix = keyPrefix;
- this.columnFamily = columnFamily;
- this.start = start;
- this.finish = finish;
- this.reversed = reversed;
- this.pageSize = pageSize;
- this.indexPath = indexPath;
- this.indexType = indexType;
- this.scanStart = start;
- }
-
-
- /* (non-Javadoc)
- * @see org.usergrid.persistence.cassandra.index.IndexScanner#reset()
- */
- @Override
- public void reset() {
- hasMore = true;
- start = scanStart;
- }
-
-
- /**
- * Search the collection index using all the buckets for the given collection. Load the next page. Return false if
- * nothing was loaded, true otherwise
- *
- * @return True if the data could be loaded
- */
-
- public boolean load() throws Exception {
-
- // nothing left to load
- if ( !hasMore ) {
- return false;
- }
-
- List<String> keys = indexBucketLocator.getBuckets( applicationId, indexType, indexPath );
-
- List<Object> cassKeys = new ArrayList<Object>( keys.size() );
-
- for ( String bucket : keys ) {
- cassKeys.add( key( keyPrefix, bucket ) );
- }
-
- //if we skip the first we need to set the load to page size +2, since we'll discard the first
- //and start paging at the next entity, otherwise we'll just load the page size we need
- int selectSize = pageSize + 1;
-
- TreeSet<HColumn<ByteBuffer, ByteBuffer>> resultsTree = IndexMultiBucketSetLoader
- .load( cass, columnFamily, applicationId, cassKeys, start, finish, selectSize, reversed );
-
- // we loaded a full page, there might be more
- if ( resultsTree.size() == selectSize ) {
- hasMore = true;
-
- // set the bytebuffer for the next pass
- start = resultsTree.last().getName();
-
- resultsTree.remove( resultsTree.last() );
- }
- else {
- hasMore = false;
- }
-
- lastResults = resultsTree;
-
- return lastResults != null && lastResults.size() > 0;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Iterable#iterator()
- */
- @Override
- public Iterator<Set<HColumn<ByteBuffer, ByteBuffer>>> iterator() {
- return this;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#hasNext()
- */
- @Override
- public boolean hasNext() {
-
- // We've either 1) paged everything we should and have 1 left from our
- // "next page" pointer
- // Our currently buffered results don't exist or don't have a next. Try to
- // load them again if they're less than the page size
- if ( lastResults == null && hasMore ) {
- try {
- return load();
- }
- catch ( Exception e ) {
- throw new RuntimeException( "Error loading next page of indexbucket scanner", e );
- }
- }
-
- return false;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#next()
- */
- @Override
- @Metered(group = "core", name = "IndexBucketScanner_load")
- public NavigableSet<HColumn<ByteBuffer, ByteBuffer>> next() {
- NavigableSet<HColumn<ByteBuffer, ByteBuffer>> returnVal = lastResults;
-
- lastResults = null;
-
- return returnVal;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#remove()
- */
- @Override
- public void remove() {
- throw new UnsupportedOperationException( "You can't remove from a result set, only advance" );
- }
-
-
- /* (non-Javadoc)
- * @see org.usergrid.persistence.cassandra.index.IndexScanner#getPageSize()
- */
- @Override
- public int getPageSize() {
- return pageSize;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c2acbe4/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/IndexMultiBucketSetLoader.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/IndexMultiBucketSetLoader.java b/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/IndexMultiBucketSetLoader.java
deleted file mode 100644
index 7a26d66..0000000
--- a/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/IndexMultiBucketSetLoader.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * 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.usergrid.persistence.cassandra.index;
-
-
-import java.nio.ByteBuffer;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeSet;
-import java.util.UUID;
-
-import org.usergrid.persistence.cassandra.ApplicationCF;
-import org.usergrid.persistence.cassandra.CassandraService;
-
-import org.apache.cassandra.db.marshal.AbstractType;
-import org.apache.cassandra.db.marshal.TypeParser;
-
-import me.prettyprint.hector.api.beans.HColumn;
-
-
-/** @author tnine */
-public class IndexMultiBucketSetLoader {
-
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
-
- /**
- * Loads and sorts columns from each bucket in memory. This will return a contiguous set of columns as if they'd
- * been
- * read from a single row
- */
- public static TreeSet<HColumn<ByteBuffer, ByteBuffer>> load( CassandraService cass, ApplicationCF columnFamily,
- UUID applicationId, List<Object> rowKeys, Object start,
- Object finish, int resultSize, boolean reversed )
- throws Exception {
- Map<ByteBuffer, List<HColumn<ByteBuffer, ByteBuffer>>> results =
- cass.multiGetColumns( cass.getApplicationKeyspace( applicationId ), columnFamily, rowKeys, start,
- finish, resultSize, reversed );
-
- final Comparator<ByteBuffer> comparator = reversed ? new DynamicCompositeReverseComparator( columnFamily ) :
- new DynamicCompositeForwardComparator( columnFamily );
-
- TreeSet<HColumn<ByteBuffer, ByteBuffer>> resultsTree =
- new TreeSet<HColumn<ByteBuffer, ByteBuffer>>( new Comparator<HColumn<ByteBuffer, ByteBuffer>>() {
-
- @Override
- public int compare( HColumn<ByteBuffer, ByteBuffer> first,
- HColumn<ByteBuffer, ByteBuffer> second ) {
-
- return comparator.compare( first.getName(), second.getName() );
- }
- } );
-
- for ( List<HColumn<ByteBuffer, ByteBuffer>> cols : results.values() ) {
-
- for ( HColumn<ByteBuffer, ByteBuffer> col : cols ) {
- resultsTree.add( col );
-
- // trim if we're over size
- if ( resultsTree.size() > resultSize ) {
- resultsTree.pollLast();
- }
- }
- }
-
- return resultsTree;
- }
-
-
- private static abstract class DynamicCompositeComparator implements Comparator<ByteBuffer> {
- @SuppressWarnings("rawtypes")
- protected final AbstractType dynamicComposite;
-
-
- protected DynamicCompositeComparator( ApplicationCF cf ) {
- // should never happen, this will blow up during development if this fails
- try {
- dynamicComposite = TypeParser.parse( cf.getComparator() );
- }
- catch ( Exception e ) {
- throw new RuntimeException( e );
- }
- }
- }
-
-
- private static class DynamicCompositeForwardComparator extends DynamicCompositeComparator {
-
- /**
- * @param cf
- */
- protected DynamicCompositeForwardComparator( ApplicationCF cf ) {
- super( cf );
- }
-
-
- @SuppressWarnings("unchecked")
- @Override
- public int compare( ByteBuffer o1, ByteBuffer o2 ) {
- return dynamicComposite.compare( o1, o2 );
- }
- }
-
-
- private static class DynamicCompositeReverseComparator extends DynamicCompositeComparator {
- /**
- * @param cf
- */
- protected DynamicCompositeReverseComparator( ApplicationCF cf ) {
- super( cf );
- }
-
-
- @SuppressWarnings("unchecked")
- @Override
- public int compare( ByteBuffer o1, ByteBuffer o2 ) {
- return dynamicComposite.compare( o2, o1 );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c2acbe4/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/IndexScanner.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/IndexScanner.java b/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/IndexScanner.java
deleted file mode 100644
index d87f37a..0000000
--- a/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/IndexScanner.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * 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.usergrid.persistence.cassandra.index;
-
-
-import java.nio.ByteBuffer;
-import java.util.Iterator;
-import java.util.Set;
-
-import me.prettyprint.hector.api.beans.HColumn;
-
-
-/**
- * Interface for scanning all index buckets.
- *
- * @author tnine
- */
-public interface IndexScanner
- extends Iterable<Set<HColumn<ByteBuffer, ByteBuffer>>>, Iterator<Set<HColumn<ByteBuffer, ByteBuffer>>> {
-
- /** Reset the scanner back to the start */
- public void reset();
-
- public int getPageSize();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c2acbe4/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/NoOpIndexScanner.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/NoOpIndexScanner.java b/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/NoOpIndexScanner.java
deleted file mode 100644
index d948af8..0000000
--- a/stack/core/src/main/java/org/usergrid/persistence/cassandra/index/NoOpIndexScanner.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * 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.usergrid.persistence.cassandra.index;
-
-
-import java.nio.ByteBuffer;
-import java.util.Iterator;
-import java.util.NavigableSet;
-import java.util.Set;
-
-import me.prettyprint.hector.api.beans.HColumn;
-
-
-/**
- * Index scanner that doesn't return anything. This is used if our cursor has advanced beyond the end of all scannable
- * ranges
- *
- * @author tnine
- */
-public class NoOpIndexScanner implements IndexScanner {
-
- /**
- *
- */
- public NoOpIndexScanner() {
- }
-
-
- /* (non-Javadoc)
- * @see java.lang.Iterable#iterator()
- */
- @Override
- public Iterator<Set<HColumn<ByteBuffer, ByteBuffer>>> iterator() {
- return this;
- }
-
-
- /* (non-Javadoc)
- * @see java.util.Iterator#hasNext()
- */
- @Override
- public boolean hasNext() {
- return false;
- }
-
-
- /* (non-Javadoc)
- * @see org.usergrid.persistence.cassandra.index.IndexScanner#reset()
- */
- @Override
- public void reset() {
- //no op
- }
-
-
- /* (non-Javadoc)
- * @see java.util.Iterator#next()
- */
- @Override
- public NavigableSet<HColumn<ByteBuffer, ByteBuffer>> next() {
- return null;
- }
-
-
- /* (non-Javadoc)
- * @see java.util.Iterator#remove()
- */
- @Override
- public void remove() {
- throw new UnsupportedOperationException( "Remove is not supported" );
- }
-
-
- /* (non-Javadoc)
- * @see org.usergrid.persistence.cassandra.index.IndexScanner#getPageSize()
- */
- @Override
- public int getPageSize() {
- return 0;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c2acbe4/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/Slf4jTraceTagReporter.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/Slf4jTraceTagReporter.java b/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/Slf4jTraceTagReporter.java
deleted file mode 100644
index 753b149..0000000
--- a/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/Slf4jTraceTagReporter.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package org.usergrid.persistence.cassandra.util;
-
-
-import java.util.Date;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * Simple reporter which dumps to class logger at info level.
- * <p/>
- * You can configure a logger with the name "TraceTagReporter" explicitly which, if not in a logging context, then the
- * class level logger will be used.
- *
- * @author zznate
- */
-public class Slf4jTraceTagReporter implements TraceTagReporter {
- private Logger logger;
-
-
- public Slf4jTraceTagReporter() {
- logger = LoggerFactory.getLogger( "TraceTagReporter" );
- if ( logger == null ) {
- logger = LoggerFactory.getLogger( Slf4jTraceTagReporter.class );
- }
- }
-
-
- @Override
- public void report( TraceTag traceTag ) {
- logger.info( "TraceTag: {}", traceTag.getTraceName() );
- for ( TimedOpTag timedOpTag : traceTag ) {
- logger.info( "----opId: {} opName: {} startTime: {} elapsed: {}", new Object[] {
- timedOpTag.getOpTag(), timedOpTag.getTagName(), new Date( timedOpTag.getStart() ),
- timedOpTag.getElapsed()
- } );
- }
- logger.info( "------" );
- }
-
-
- @Override
- public void reportUnattached( TimedOpTag timedOpTag ) {
- logger.info( "--[unattached]-- {}", timedOpTag );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c2acbe4/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TaggedOpTimer.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TaggedOpTimer.java b/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TaggedOpTimer.java
deleted file mode 100644
index d0cef79..0000000
--- a/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TaggedOpTimer.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.usergrid.persistence.cassandra.util;
-
-
-import me.prettyprint.cassandra.connection.HOpTimer;
-
-
-/**
- * Trace the timed execution of a 'tag' over the course of a number of operations. Facilitates integration with
- * Dapper-style trace logging infrastructure.
- *
- * @author zznate
- */
-public class TaggedOpTimer implements HOpTimer {
-
- private TraceTagManager traceTagManager;
-
-
- public TaggedOpTimer( TraceTagManager traceTagManager ) {
- this.traceTagManager = traceTagManager;
- }
-
-
- @Override
- public Object start( String tagName ) {
- // look for our threadLocal. if not present, return this.
- return traceTagManager.timerInstance();
- }
-
-
- @Override
- public void stop( Object timedOpTag, String opTagName, boolean success ) {
- if ( timedOpTag instanceof TimedOpTag ) {
- TimedOpTag t = ( ( TimedOpTag ) timedOpTag );
- t.stopAndApply( opTagName, success );
- traceTagManager.addTimer( t );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c2acbe4/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TimedOpTag.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TimedOpTag.java b/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TimedOpTag.java
deleted file mode 100644
index d30c2f2..0000000
--- a/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TimedOpTag.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package org.usergrid.persistence.cassandra.util;
-
-
-import java.util.UUID;
-
-import org.usergrid.utils.UUIDUtils;
-
-import com.google.common.base.Objects;
-
-
-/**
- * Simple struct holding timer information for an operation and an arbitrary tag for spanning 0 or more operations
- *
- * @author zznate
- */
-public class TimedOpTag {
-
- private final UUID opTag;
- private final String traceTagName;
- private String tagName;
- private long elapsed = 0;
- private boolean status;
-
-
- private TimedOpTag( TraceTag trace ) {
- this.opTag = UUIDUtils.newTimeUUID();
- this.traceTagName = ( trace != null ? trace.getTraceName() : "-NONE-" );
- }
-
-
- /**
- * Get an instance with the current start timer set to 'now'
- *
- * @param traceTag can be null for single op timing
- */
- public static TimedOpTag instance( TraceTag traceTag ) {
- return new TimedOpTag( traceTag );
- }
-
-
- /** Apply tagName only if not already applied */
- public void stopAndApply( String tName, boolean opStatus ) {
- if ( elapsed == 0 ) {
- // extract from uuid and calculate
- elapsed = System.currentTimeMillis() - UUIDUtils.getTimestampInMillis( opTag );
- }
- if ( tName != null ) {
- this.tagName = tName;
- this.status = opStatus;
- }
- }
-
-
- /** Elapsed time of this op in milliseconds. */
- public long getElapsed() {
- return elapsed;
- }
-
-
- /**
- * The start time of this operation as represented by the timestamp embedded in the type-1 UUID of the opTag
- * property
- */
- public long getStart() {
- return UUIDUtils.getTimestampInMillis( opTag );
- }
-
-
- /** The tag for this specific operation */
- public UUID getOpTag() {
- return opTag;
- }
-
-
- /** A tag which may span 0 or more operations */
- public String getTraceTagName() {
- return traceTagName;
- }
-
-
- /** @return the tagName - null if never applied */
- public String getTagName() {
- return tagName;
- }
-
-
- /**
- * @return whether or not the operation was 'successful' Could still be false if {@link #stopAndApply(String,
- * boolean)} was never called
- */
- public boolean getOpSuccessful() {
- return status;
- }
-
-
- @Override
- public String toString() {
- return Objects.toStringHelper( this ).add( "traceTag", traceTagName ).add( "opTag", opTag.toString() )
- .add( "tagName", tagName ).add( "start", getStart() ).add( "elapsed", elapsed ).toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c2acbe4/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceParticipant.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceParticipant.java b/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceParticipant.java
deleted file mode 100644
index 3f8b9d9..0000000
--- a/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceParticipant.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.usergrid.persistence.cassandra.util;
-
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-
-/**
- * Mark a method as able to participate in a trace session
- *
- * @author zznate
- */
-@Target(value = { ElementType.METHOD })
-@Retention(RetentionPolicy.RUNTIME)
-public @interface TraceParticipant {
-
- String name() default "";
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c2acbe4/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceTag.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceTag.java b/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceTag.java
deleted file mode 100644
index 0c6250f..0000000
--- a/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceTag.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package org.usergrid.persistence.cassandra.util;
-
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.UUID;
-
-
-/** @author zznate */
-public class TraceTag implements Iterable<TimedOpTag> {
-
- private final UUID tag;
- private final String name;
- private final String traceName;
- private final List<TimedOpTag> timedOps;
- private final boolean metered;
-
-
- private TraceTag( UUID tag, String name, boolean metered ) {
- this.tag = tag;
- this.name = name;
- this.metered = metered;
- traceName = new StringBuilder( this.tag.toString() ).append( "-" ).append( this.metered ).append( "-" )
- .append( this.name ).toString();
- timedOps = new ArrayList<TimedOpTag>();
- }
-
-
- public static TraceTag getInstance( UUID tag, String name ) {
- return new TraceTag( tag, name, false );
- }
-
-
- public static TraceTag getMeteredInstance( UUID tag, String name ) {
- return new TraceTag( tag, name, true );
- }
-
-
- public String getTraceName() {
- return traceName;
- }
-
-
- public void add( TimedOpTag timedOpTag ) {
- timedOps.add( timedOpTag );
- }
-
-
- public boolean getMetered() {
- return metered;
- }
-
-
- @Override
- public String toString() {
- return getTraceName();
- }
-
-
- @Override
- public Iterator iterator() {
- return timedOps.iterator();
- }
-
-
- /** The number of {@link TimedOpTag} instances currently held */
- public int getOpCount() {
- return timedOps.size();
- }
-
-
- /** Remove the currently held {@link TimedOpTag} instances */
- public void removeOps() {
- timedOps.clear();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c2acbe4/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceTagAspect.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceTagAspect.java b/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceTagAspect.java
deleted file mode 100644
index 30166d7..0000000
--- a/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceTagAspect.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.usergrid.persistence.cassandra.util;
-
-
-import javax.annotation.Resource;
-
-import org.aspectj.lang.ProceedingJoinPoint;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * Use Aspects to apply a trace
- *
- * @author zznate
- */
-public class TraceTagAspect {
- private static final Logger logger = LoggerFactory.getLogger( TraceTagAspect.class );
-
- @Resource
- private TraceTagManager traceTagManager;
-
-
- public Object applyTrace( ProceedingJoinPoint pjp ) throws Throwable {
- String tagName = pjp.toLongString();
- logger.debug( "Applyng trace on {}", tagName );
- TimedOpTag timedOpTag = traceTagManager.timerInstance();
- boolean success = true;
- try {
- return pjp.proceed();
- }
- catch ( Exception e ) {
- success = false;
- throw e;
- }
- finally {
- timedOpTag.stopAndApply( tagName, success );
- traceTagManager.addTimer( timedOpTag );
- logger.debug( "TimedOpTag added in Aspect on {}", tagName );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c2acbe4/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceTagManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceTagManager.java b/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceTagManager.java
deleted file mode 100644
index 6cdeb3a..0000000
--- a/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceTagManager.java
+++ /dev/null
@@ -1,156 +0,0 @@
-package org.usergrid.persistence.cassandra.util;
-
-
-import javax.annotation.Resource;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.usergrid.utils.UUIDUtils;
-
-import com.google.common.base.Preconditions;
-
-
-/**
- * Keeps the TraceTag as a ThreadLocal
- *
- * @author zznate
- */
-public class TraceTagManager {
- private Logger logger = LoggerFactory.getLogger( TraceTagManager.class );
-
- private static ThreadLocal<TraceTag> localTraceTag = new ThreadLocal<TraceTag>();
-
- private boolean traceEnabled;
-
- private boolean reportUnattached;
-
- private boolean explicitOnly;
-
- private int flushAtOpCount = 100;
-
- @Resource
- private TraceTagReporter traceTagReporter;
-
-
- /** Enable tracing. Off by default. */
- public void setTraceEnabled( boolean traceEnabled ) {
- this.traceEnabled = traceEnabled;
- }
-
-
- public boolean getTraceEnabled() {
- return traceEnabled;
- }
-
-
- /**
- * The maximum number of o TimedOpTag objects we can attach to a tracing instance. Excess of this will for a
- * blocking flush on the current thread to the configured reporter instance.
- * <p/>
- * The default is 100. If you have other ThreadLocal variables, you should probably lower this value.
- */
- public int getFlushAtOpCount() {
- return flushAtOpCount;
- }
-
-
- public void setFlushAtOpCount( int flushAtOpCount ) {
- this.flushAtOpCount = flushAtOpCount;
- }
-
-
- /** If set to true we log all TimedOpTag objects not attached to a Trace */
- public void setReportUnattached( boolean reportUnattached ) {
- this.reportUnattached = reportUnattached;
- }
-
-
- /**
- * Allow for/check against traces in piecemeal. Use this when {@link #setTraceEnabled(boolean)} is set to false and
- * you want callers to control whether or not to initiate a trace. An example would be initiating traces in a
- * ServletFilter by looking for a header or parameter as tracing all requests would be expensive.
- */
- public boolean getExplicitOnly() {
- return explicitOnly;
- }
-
-
- public void setExplicitOnly( boolean explicitOnly ) {
- this.explicitOnly = explicitOnly;
- }
-
-
- /** Get the tag from a ThreadLocal. Will return null if no tag is attached. */
- public TraceTag acquire() {
- return localTraceTag.get();
- }
-
-
- public TimedOpTag timerInstance() {
- return TimedOpTag.instance( acquire() );
- }
-
-
- /**
- * Add this TimedOpTag to the underlying trace if there is one. Optionally log it's contents if no trace is active.
- * If an active trace was found and {@link org.usergrid.persistence.cassandra.util.TraceTag#getOpCount()} exceeded
- * {@link #getFlushAtOpCount()}, then the trace is dumped to the reporter and {@link
- * org.usergrid.persistence.cassandra.util.TraceTag#removeOps()} is invoked. The TraceTag stay attached with the
- * same name and ID, but now with no pending ops.
- */
- public void addTimer( TimedOpTag timedOpTag ) {
- if ( isActive() ) {
- TraceTag tag = acquire();
- if ( tag.getOpCount() >= flushAtOpCount ) {
- traceTagReporter.report( tag );
- tag.removeOps();
- }
- tag.add( timedOpTag );
-
- // if TraceTag#metered, send to meter by tag name
- }
- else {
- if ( reportUnattached ) {
- traceTagReporter.reportUnattached( timedOpTag );
- }
- }
- }
-
-
- /** Returns true if there is a trace in progress */
- public boolean isActive() {
- return acquire() != null;
- }
-
-
- /**
- * Attache the tag to the current Thread. Will throw an IllegalStateException if there is already a trace in
- * progress.
- */
- public void attach( TraceTag traceTag ) {
- Preconditions.checkState( !isActive(), "Attempt to attach on already active trace" );
- localTraceTag.set( traceTag );
- logger.debug( "Attached TraceTag {} to thread", traceTag );
- }
-
-
- /** Detach the tag from the current thread. Throws an IllegalStateException if there is no trace in progress. */
- public TraceTag detach() {
- TraceTag traceTag = localTraceTag.get();
- Preconditions.checkState( isActive(), "Attempt to detach on no active trace" );
- localTraceTag.remove();
- logger.debug( "Detached TraceTag {} from thread", traceTag );
- return traceTag;
- }
-
-
- /** Create a TraceTag */
- public TraceTag create( String tagName ) {
- return TraceTag.getInstance( UUIDUtils.newTimeUUID(), tagName );
- }
-
-
- public TraceTag createMetered( String tagName ) {
- return TraceTag.getMeteredInstance( UUIDUtils.newTimeUUID(), tagName );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c2acbe4/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceTagReporter.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceTagReporter.java b/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceTagReporter.java
deleted file mode 100644
index d10e18c..0000000
--- a/stack/core/src/main/java/org/usergrid/persistence/cassandra/util/TraceTagReporter.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.usergrid.persistence.cassandra.util;
-
-
-/** @author zznate */
-public interface TraceTagReporter {
-
- void report( TraceTag traceTag );
-
- void reportUnattached( TimedOpTag timedOpTag );
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c2acbe4/stack/core/src/main/java/org/usergrid/persistence/entities/Activity.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/entities/Activity.java b/stack/core/src/main/java/org/usergrid/persistence/entities/Activity.java
deleted file mode 100644
index 81b77cb..0000000
--- a/stack/core/src/main/java/org/usergrid/persistence/entities/Activity.java
+++ /dev/null
@@ -1,685 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * 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.usergrid.persistence.entities;
-
-
-import java.util.Arrays;
-import java.util.Date;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.UUID;
-
-import javax.xml.bind.annotation.XmlRootElement;
-
-import org.codehaus.jackson.annotate.JsonAnyGetter;
-import org.codehaus.jackson.annotate.JsonAnySetter;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
-import org.usergrid.persistence.Entity;
-import org.usergrid.persistence.EntityRef;
-import org.usergrid.persistence.TypedEntity;
-import org.usergrid.persistence.annotations.EntityDictionary;
-import org.usergrid.persistence.annotations.EntityProperty;
-
-import static org.usergrid.utils.StringUtils.toStringFormat;
-
-
-/**
- * An entity type for representing activity stream actions. These are similar to the more generic message entity type
- * except provide the necessary properties for supporting activity stream implementations.
- *
- * @see http://activitystrea.ms/specs/json/1.0/
- */
-@XmlRootElement
-public class Activity extends TypedEntity {
-
- public static final String ENTITY_TYPE = "activity";
-
- public static final String PROPERTY_OBJECT_NAME = "objectName";
- public static final String PROPERTY_OBJECT_ENTITY_TYPE = "objectEntityType";
- public static final String PROPERTY_ACTOR_NAME = "actorName";
- public static final String PROPERTY_OBJECT = "object";
- public static final String PROPERTY_ACTOR = "actor";
- public static final String PROPERTY_TITLE = "title";
- public static final String PROPERTY_CONTENT = "content";
- public static final String PROPERTY_CATEGORY = "category";
- public static final String PROPERTY_VERB = "verb";
- public static final String PROPERTY_UUID = "uuid";
- public static final String PROPERTY_ENTITY_TYPE = "entityType";
- public static final String PROPERTY_OBJECT_TYPE = "objectType";
- public static final String PROPERTY_DISPLAY_NAME = "displayName";
-
- public static final String VERB_ADD = "add";
- public static final String VERB_CANCEL = "cancel";
- public static final String VERB_CHECKIN = "checkin";
- public static final String VERB_DELETE = "delete";
- public static final String VERB_FAVORITE = "favorite";
- public static final String VERB_FOLLOW = "follow";
- public static final String VERB_GIVE = "give";
- public static final String VERB_IGNORE = "ignore";
- public static final String VERB_INVITE = "invite";
- public static final String VERB_JOIN = "join";
- public static final String VERB_LEAVE = "leave";
- public static final String VERB_LIKE = "like";
- public static final String VERB_MAKE_FRIEND = "make-friend";
- public static final String VERB_PLAY = "play";
- public static final String VERB_POST = "post";
- public static final String VERB_RECEIVE = "receive";
- public static final String VERB_REMOVE = "remove";
- public static final String VERB_REMOVE_FRIEND = "remove-friend";
- public static final String VERB_REQUEST_FRIEND = "request-friend";
- public static final String VERB_RSVP_MAYBE = "rsvp-maybe";
- public static final String VERB_RSVP_NO = "rsvp-no";
- public static final String VERB_RSVP_YES = "rsvp-yes";
- public static final String VERB_SAVE = "save";
- public static final String VERB_SHARE = "share";
- public static final String VERB_STOP_FOLLOWING = "stop-following";
- public static final String VERB_TAG = "tag";
- public static final String VERB_UNFAVORITE = "unfavorite";
- public static final String VERB_UNLIKE = "unlike";
- public static final String VERB_UNSAVE = "unsave";
- public static final String VERB_UPDATE = "update";
-
- public static final String OBJECT_TYPE_ARTICLE = "article";
- public static final String OBJECT_TYPE_AUDIO = "audio";
- public static final String OBJECT_TYPE_BADGE = "badge";
- public static final String OBJECT_TYPE_BOOKMARK = "bookmark";
- public static final String OBJECT_TYPE_COLLECTION = "collection";
- public static final String OBJECT_TYPE_COMMENT = "comment";
- public static final String OBJECT_TYPE_EVENT = "event";
- public static final String OBJECT_TYPE_FILE = "file";
- public static final String OBJECT_TYPE_GROUP = "group";
- public static final String OBJECT_TYPE_IMAGE = "image";
- public static final String OBJECT_TYPE_NOTE = "note";
- public static final String OBJECT_TYPE_PERSON = "person";
- public static final String OBJECT_TYPE_PLACE = "place";
- public static final String OBJECT_TYPE_PRODUCT = "product";
- public static final String OBJECT_TYPE_QUESTION = "question";
- public static final String OBJECT_TYPE_REVIEW = "review";
- public static final String OBJECT_TYPE_SERVICE = "service";
- public static final String OBJECT_TYPE_VIDEO = "video";
-
- @EntityProperty(required = true, mutable = false, indexed = true)
- ActivityObject actor;
-
- @EntityProperty(indexed = true, fulltextIndexed = true, required = false, mutable = false)
- protected String content;
-
- ActivityObject generator;
-
- @EntityProperty(indexed = false, fulltextIndexed = false, required = false, mutable = false)
- protected MediaLink icon;
-
- @EntityProperty(fulltextIndexed = false, required = false, mutable = false, indexed = true)
- String category;
-
- @EntityProperty(fulltextIndexed = false, required = true, mutable = false, indexed = true)
- String verb;
-
- @EntityProperty(indexed = true, required = true, mutable = false, timestamp = true)
- protected Long published;
-
- @EntityProperty(indexed = false, required = false, mutable = false)
- ActivityObject object;
-
- @EntityProperty(indexed = true, fulltextIndexed = true, required = false, mutable = false)
- protected String title;
-
- @EntityDictionary(keyType = java.lang.String.class)
- protected Set<String> connections;
-
-
- public Activity() {
- // id = UUIDUtils.newTimeUUID();
- }
-
-
- public Activity( UUID id ) {
- uuid = id;
- }
-
-
- public static Activity newActivity( String verb, String title, String content, String category, Entity user,
- EntityRef object, String objectType, String objectName, String objectContent )
- throws Exception {
-
- Activity activity = new Activity();
- activity.setVerb( verb );
- activity.setCategory( category );
- activity.setContent( content );
- activity.setTitle( title );
-
- ActivityObject actor = new ActivityObject();
- actor.setObjectType( "person" );
- if ( user != null ) {
- actor.setDisplayName( ( String ) user.getProperty( "name" ) );
- actor.setEntityType( user.getType() );
- actor.setUuid( user.getUuid() );
- }
- activity.setActor( actor );
-
- ActivityObject obj = new ActivityObject();
- obj.setDisplayName( objectName );
- obj.setObjectType( objectType );
- if ( object != null ) {
- obj.setEntityType( object.getType() );
- obj.setUuid( object.getUuid() );
- }
- if ( objectContent != null ) {
- obj.setContent( objectContent );
- }
- else {
- obj.setContent( content );
- }
- activity.setObject( obj );
-
- return activity;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public ActivityObject getActor() {
- return actor;
- }
-
-
- public void setActor( ActivityObject actor ) {
- this.actor = actor;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public ActivityObject getGenerator() {
- return generator;
- }
-
-
- public void setGenerator( ActivityObject generator ) {
- this.generator = generator;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String getCategory() {
- return category;
- }
-
-
- public void setCategory( String category ) {
- this.category = category;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String getVerb() {
- return verb;
- }
-
-
- public void setVerb( String verb ) {
- this.verb = verb;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public Long getPublished() {
- return published;
- }
-
-
- public void setPublished( Long published ) {
- this.published = published;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public ActivityObject getObject() {
- return object;
- }
-
-
- public void setObject( ActivityObject object ) {
- this.object = object;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String getTitle() {
- return title;
- }
-
-
- public void setTitle( String title ) {
- this.title = title;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public MediaLink getIcon() {
- return icon;
- }
-
-
- public void setIcon( MediaLink icon ) {
- this.icon = icon;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String getContent() {
- return content;
- }
-
-
- public void setContent( String content ) {
- this.content = content;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public Set<String> getConnections() {
- return connections;
- }
-
-
- public void setConnections( Set<String> connections ) {
- this.connections = connections;
- }
-
-
- @XmlRootElement
- static public class MediaLink {
-
- int duration;
-
- int height;
-
- String url;
-
- int width;
-
- protected Map<String, Object> dynamic_properties = new TreeMap<String, Object>( String.CASE_INSENSITIVE_ORDER );
-
-
- public MediaLink() {
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public int getDuration() {
- return duration;
- }
-
-
- public void setDuration( int duration ) {
- this.duration = duration;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public int getHeight() {
- return height;
- }
-
-
- public void setHeight( int height ) {
- this.height = height;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String getUrl() {
- return url;
- }
-
-
- public void setUrl( String url ) {
- this.url = url;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public int getWidth() {
- return width;
- }
-
-
- public void setWidth( int width ) {
- this.width = width;
- }
-
-
- @JsonAnySetter
- public void setDynamicProperty( String key, Object value ) {
- dynamic_properties.put( key, value );
- }
-
-
- @JsonAnyGetter
- public Map<String, Object> getDynamicProperties() {
- return dynamic_properties;
- }
-
-
- @Override
- public String toString() {
- return "MediaLink [duration=" + duration + ", height=" + height + ", url=" + url + ", width=" + width
- + ", dynamic_properties=" + dynamic_properties + "]";
- }
- }
-
-
- @XmlRootElement
- static public class ActivityObject {
-
- ActivityObject[] attachments;
-
- ActivityObject author;
-
- String content;
-
- String displayName;
-
- String[] downstreamDuplicates;
-
- String id;
-
- MediaLink image;
-
- String objectType;
-
- Date published;
-
- String summary;
-
- String updated;
-
- String upstreamDuplicates;
-
- String url;
-
- UUID uuid;
-
- String entityType;
-
- protected Map<String, Object> dynamic_properties = new TreeMap<String, Object>( String.CASE_INSENSITIVE_ORDER );
-
-
- public ActivityObject() {
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public ActivityObject[] getAttachments() {
- return attachments;
- }
-
-
- public void setAttachments( ActivityObject[] attachments ) {
- this.attachments = attachments;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public ActivityObject getAuthor() {
- return author;
- }
-
-
- public void setAuthor( ActivityObject author ) {
- this.author = author;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String getContent() {
- return content;
- }
-
-
- public void setContent( String content ) {
- this.content = content;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String getDisplayName() {
- return displayName;
- }
-
-
- public void setDisplayName( String displayName ) {
- this.displayName = displayName;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String[] getDownstreamDuplicates() {
- return downstreamDuplicates;
- }
-
-
- public void setDownstreamDuplicates( String[] downstreamDuplicates ) {
- this.downstreamDuplicates = downstreamDuplicates;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String getId() {
- return id;
- }
-
-
- public void setId( String id ) {
- this.id = id;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public MediaLink getImage() {
- return image;
- }
-
-
- public void setImage( MediaLink image ) {
- this.image = image;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String getObjectType() {
- return objectType;
- }
-
-
- public void setObjectType( String objectType ) {
- this.objectType = objectType;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public Date getPublished() {
- return published;
- }
-
-
- public void setPublished( Date published ) {
- this.published = published;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String getSummary() {
- return summary;
- }
-
-
- public void setSummary( String summary ) {
- this.summary = summary;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String getUpdated() {
- return updated;
- }
-
-
- public void setUpdated( String updated ) {
- this.updated = updated;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String getUpstreamDuplicates() {
- return upstreamDuplicates;
- }
-
-
- public void setUpstreamDuplicates( String upstreamDuplicates ) {
- this.upstreamDuplicates = upstreamDuplicates;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String getUrl() {
- return url;
- }
-
-
- public void setUrl( String url ) {
- this.url = url;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public UUID getUuid() {
- return uuid;
- }
-
-
- public void setUuid( UUID uuid ) {
- this.uuid = uuid;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String getEntityType() {
- return entityType;
- }
-
-
- public void setEntityType( String entityType ) {
- this.entityType = entityType;
- }
-
-
- @JsonAnySetter
- public void setDynamicProperty( String key, Object value ) {
- dynamic_properties.put( key, value );
- }
-
-
- @JsonAnyGetter
- public Map<String, Object> getDynamicProperties() {
- return dynamic_properties;
- }
-
-
- @Override
- public String toString() {
- return "ActivityObject [" + toStringFormat( attachments, "attachments=%s, " ) + toStringFormat( author,
- "author=%s, " ) + toStringFormat( content, "content=%s, " ) + toStringFormat( displayName,
- "displayName=%s, " ) + toStringFormat( downstreamDuplicates, "downstreamDuplicates=%s, " )
- + toStringFormat( id, "id=%s, " ) + toStringFormat( image, "image=%s, " ) + toStringFormat(
- objectType, "objectType=%s, " ) + toStringFormat( published, "published=%s, " ) + toStringFormat(
- summary, "summary=%s, " ) + toStringFormat( updated, "updated=%s, " ) + toStringFormat(
- upstreamDuplicates, "upstreamDuplicates=%s, " ) + toStringFormat( url, "url=%s, " )
- + toStringFormat( uuid, "uuid=%s, " ) + toStringFormat( entityType, "entityType=%s, " )
- + toStringFormat( dynamic_properties, "dynamic_properties=%s" ) + "]";
- }
- }
-
-
- @XmlRootElement
- static public class ActivityCollection {
-
- int totalItems;
-
- ActivityObject[] items;
-
- String url;
-
- protected Map<String, Object> dynamic_properties = new TreeMap<String, Object>( String.CASE_INSENSITIVE_ORDER );
-
-
- public ActivityCollection() {
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public int getTotalItems() {
- return totalItems;
- }
-
-
- public void setTotalItems( int totalItems ) {
- this.totalItems = totalItems;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public ActivityObject[] getItems() {
- return items;
- }
-
-
- public void setItems( ActivityObject[] items ) {
- this.items = items;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String getUrl() {
- return url;
- }
-
-
- public void setUrl( String url ) {
- this.url = url;
- }
-
-
- @JsonAnySetter
- public void setDynamicProperty( String key, Object value ) {
- dynamic_properties.put( key, value );
- }
-
-
- @JsonAnyGetter
- public Map<String, Object> getDynamicProperties() {
- return dynamic_properties;
- }
-
-
- @Override
- public String toString() {
- return "ActivityCollection [totalItems=" + totalItems + ", items=" + Arrays.toString( items ) + ", url="
- + url + ", dynamic_properties=" + dynamic_properties + "]";
- }
- }
-}