001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Sam
027: */
028:
029: package com.caucho.server.admin;
030:
031: import com.caucho.config.ConfigException;
032: import com.caucho.server.cluster.Cluster;
033: import com.caucho.transaction.TransactionManagerImpl;
034: import com.caucho.transaction.xalog.AbstractXALogManager;
035: import com.caucho.util.L10N;
036: import com.caucho.vfs.Vfs;
037:
038: import java.io.IOException;
039: import java.util.logging.Level;
040: import java.util.logging.Logger;
041:
042: public class TransactionLog {
043: private static final Logger log = Logger
044: .getLogger(TransactionLog.class.getName());
045: private static final L10N L = new L10N(TransactionLog.class);
046:
047: private final TransactionManager _manager;
048:
049: private boolean _isEnable = true;
050: private String _path;
051: private AbstractXALogManager _xaLog;
052:
053: public TransactionLog(TransactionManager manager) {
054: _manager = manager;
055: }
056:
057: public void setPath(String path) throws IOException {
058: _path = path;
059: }
060:
061: public boolean isEnable() {
062: return _isEnable;
063: }
064:
065: public void setEnable(boolean enable) {
066: _isEnable = enable;
067: }
068:
069: public void start() {
070: if (_path == null) {
071: String serverId = Cluster.getServerId();
072:
073: if (serverId == null || serverId.length() == 0)
074: serverId = "default";
075:
076: _path = "xa-" + serverId + ".log";
077: }
078:
079: if (!_isEnable)
080: return;
081:
082: try {
083: Class cl = Class
084: .forName("com.caucho.transaction.xalog.XALogManager");
085:
086: _xaLog = (AbstractXALogManager) cl.newInstance();
087: } catch (Throwable e) {
088: log.log(Level.FINER, e.toString(), e);
089: }
090:
091: if (_xaLog == null)
092: throw new ConfigException(
093: L
094: .l("<transaction-log> requires Resin Professional. See http://www.caucho.com for information and licensing."));
095:
096: try {
097: if (_manager.getPath() != null)
098: _xaLog.setPath(_manager.getPath().lookup(_path));
099: else
100: _xaLog.setPath(Vfs.lookup(_path));
101:
102: TransactionManagerImpl tm = TransactionManagerImpl
103: .getLocal();
104:
105: tm.setXALogManager(_xaLog);
106:
107: _xaLog.start();
108: } catch (IOException e) {
109: throw ConfigException.create(e);
110: }
111: }
112:
113: public void destroy() {
114: AbstractXALogManager xaLog = _xaLog;
115: _xaLog = null;
116:
117: if (xaLog != null) {
118: try {
119: xaLog.close();
120: } catch (Exception ex) {
121: log.log(Level.INFO, ex.toString(), ex);
122: }
123: }
124:
125: }
126: }
|