View Javadoc

1   package org.csc.phynixx.tutorial;
2   
3   /*
4    * #%L
5    * phynixx-tutorial
6    * %%
7    * Copyright (C) 2014 Christoph Schmidt-Casdorff
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  
24  import org.csc.phynixx.common.exceptions.DelegatedRuntimeException;
25  import org.csc.phynixx.common.generator.IDGenerator;
26  import org.csc.phynixx.common.generator.IDGenerators;
27  
28  import java.io.File;
29  
30  /**
31   * Created by Christoph Schmidt-Casdorff on 04.02.14.
32   */
33  public class TAEnabledUTFWriterFactoryImpl implements TAEnabledUTFWriterFactory {
34  
35      private static final IDGenerator<Long> idGenerator= IDGenerators.createLongGenerator(1,true);
36  
37      private final UTFWriter sharedWriter;
38  
39  
40      public TAEnabledUTFWriterFactoryImpl(File sharedFile) {
41          this.sharedWriter = new UTFWriterImpl(sharedFile);
42      }
43  
44      @Override
45      public TAEnabledUTFWriter getConnection() {
46          try {
47              return new TAEnabledUTFWriterImpl(Long.toString(idGenerator.generate()), this.sharedWriter);
48          } catch (Exception e) {
49             throw new DelegatedRuntimeException(e);
50          }
51      }
52  
53      @Override
54      public Class<TAEnabledUTFWriter> getConnectionInterface() {
55          return TAEnabledUTFWriter.class;
56      }
57  
58      @Override
59      public void close() {
60          this.sharedWriter.close();
61  
62      }
63  }