View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.directmemory.tests.osgi.cache;
21  
22  import org.apache.directmemory.DirectMemory;
23  import org.apache.directmemory.cache.CacheService;
24  import org.apache.directmemory.measures.Ram;
25  import org.apache.directmemory.memory.MemoryManagerService;
26  import org.apache.directmemory.memory.MemoryManagerServiceImpl;
27  import org.apache.directmemory.serialization.SerializerFactory;
28  import org.apache.directmemory.serialization.StandardSerializer;
29  import org.osgi.framework.BundleActivator;
30  import org.osgi.framework.BundleContext;
31  
32  import java.util.Properties;
33  
34  public class CacheServiceExportingActivator
35      implements BundleActivator
36  {
37  
38      CacheService<String, SimpleObject> cacheService;
39  
40      @Override
41      public void start( BundleContext context )
42          throws Exception
43      {
44          MemoryManagerService<SimpleObject> memoryManager =
45              new MemoryManagerServiceImpl<SimpleObject>();
46          this.cacheService =
47              new DirectMemory<String, SimpleObject>().setNumberOfBuffers( 1 ).setSize( Ram.Mb( 1 ) ).setMemoryManager(
48                  memoryManager ).setSerializer(
49                  SerializerFactory.createNewSerializer( StandardSerializer.class ) ).newCacheService();
50          cacheService.put( "1", new SimpleObject( "1,", "Activator Object" ) );
51          context.registerService( CacheService.class.getCanonicalName(), cacheService, new Properties() );
52  
53          /*CacheService<Integer, byte[]> cache = new DirectMemory<Integer, byte[]>()
54          .setMemoryManager( memoryManager )
55          .setNumberOfBuffers( 1 )
56          .setSize(  )
57          .newCacheService();*/
58      }
59  
60      @Override
61      public void stop( BundleContext context )
62          throws Exception
63      {
64      }
65  }