| /* |
| * Copyright 2009-2010 by The Regents of the University of California |
| * 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 from |
| * |
| * 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 edu.uci.ics.hyracks.examples.btree.helper; |
| |
| import java.util.concurrent.ThreadFactory; |
| |
| import edu.uci.ics.hyracks.api.application.INCApplicationContext; |
| import edu.uci.ics.hyracks.api.context.IHyracksTaskContext; |
| import edu.uci.ics.hyracks.api.exceptions.HyracksDataException; |
| import edu.uci.ics.hyracks.storage.am.common.api.IIndexLifecycleManager; |
| import edu.uci.ics.hyracks.storage.am.common.dataflow.IndexLifecycleManager; |
| import edu.uci.ics.hyracks.storage.common.buffercache.BufferCache; |
| import edu.uci.ics.hyracks.storage.common.buffercache.ClockPageReplacementStrategy; |
| import edu.uci.ics.hyracks.storage.common.buffercache.DelayPageCleanerPolicy; |
| import edu.uci.ics.hyracks.storage.common.buffercache.HeapBufferAllocator; |
| import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache; |
| import edu.uci.ics.hyracks.storage.common.buffercache.ICacheMemoryAllocator; |
| import edu.uci.ics.hyracks.storage.common.buffercache.IPageReplacementStrategy; |
| import edu.uci.ics.hyracks.storage.common.file.IFileMapManager; |
| import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider; |
| import edu.uci.ics.hyracks.storage.common.file.ILocalResourceRepository; |
| import edu.uci.ics.hyracks.storage.common.file.ILocalResourceRepositoryFactory; |
| import edu.uci.ics.hyracks.storage.common.file.ResourceIdFactory; |
| import edu.uci.ics.hyracks.storage.common.file.ResourceIdFactoryProvider; |
| import edu.uci.ics.hyracks.storage.common.file.TransientFileMapManager; |
| import edu.uci.ics.hyracks.storage.common.file.TransientLocalResourceRepositoryFactory; |
| |
| public class RuntimeContext { |
| private IBufferCache bufferCache; |
| private IFileMapManager fileMapManager; |
| private ILocalResourceRepository localResourceRepository; |
| private IIndexLifecycleManager lcManager; |
| private ResourceIdFactory resourceIdFactory; |
| private ThreadFactory threadFactory = new ThreadFactory() { |
| public Thread newThread(Runnable r) { |
| return new Thread(r); |
| } |
| }; |
| |
| public RuntimeContext(INCApplicationContext appCtx) throws HyracksDataException { |
| fileMapManager = new TransientFileMapManager(); |
| ICacheMemoryAllocator allocator = new HeapBufferAllocator(); |
| IPageReplacementStrategy prs = new ClockPageReplacementStrategy(); |
| bufferCache = new BufferCache(appCtx.getRootContext().getIOManager(), allocator, prs, |
| new DelayPageCleanerPolicy(1000), fileMapManager, 32768, 50, 100, threadFactory); |
| lcManager = new IndexLifecycleManager(); |
| ILocalResourceRepositoryFactory localResourceRepositoryFactory = new TransientLocalResourceRepositoryFactory(); |
| localResourceRepository = localResourceRepositoryFactory.createRepository(); |
| resourceIdFactory = (new ResourceIdFactoryProvider(localResourceRepository)).createResourceIdFactory(); |
| } |
| |
| public void close() throws HyracksDataException { |
| bufferCache.close(); |
| } |
| |
| public IBufferCache getBufferCache() { |
| return bufferCache; |
| } |
| |
| public IFileMapProvider getFileMapManager() { |
| return fileMapManager; |
| } |
| |
| public static RuntimeContext get(IHyracksTaskContext ctx) { |
| return (RuntimeContext) ctx.getJobletContext().getApplicationContext().getApplicationObject(); |
| } |
| |
| public ILocalResourceRepository getLocalResourceRepository() { |
| return localResourceRepository; |
| } |
| |
| public ResourceIdFactory getResourceIdFactory() { |
| return resourceIdFactory; |
| } |
| |
| public IIndexLifecycleManager getIndexLifecycleManager() { |
| return lcManager; |
| } |
| } |