Search in sources :

Example 1 with FatalError

use of com.arjuna.ats.arjuna.exceptions.FatalError in project narayana by jbosstm.

the class DynamicDataSourceJDBCAccess method initialise.

public void initialise(StringTokenizer tokenizer) {
    while (tokenizer.hasMoreElements()) {
        Map<String, String> configuration = new HashMap<String, String>();
        while (tokenizer.hasMoreTokens()) {
            String[] split = tokenizer.nextToken().split("=");
            configuration.put(split[0], split[1].replace("\\equ", "="));
        }
        try {
            this.dataSource = (DataSource) Class.forName(configuration.remove("ClassName")).newInstance();
            Iterator<String> iterator = configuration.keySet().iterator();
            while (iterator.hasNext()) {
                String key = iterator.next();
                String value = configuration.get(key);
                Method method = null;
                try {
                    method = dataSource.getClass().getMethod("set" + key, java.lang.String.class);
                    String replace = value.replace("\\semi", ";");
                    method.invoke(dataSource, value.replace("\\semi", ";"));
                } catch (NoSuchMethodException nsme) {
                    method = dataSource.getClass().getMethod("set" + key, int.class);
                    method.invoke(dataSource, Integer.valueOf(value));
                }
            }
        } catch (Exception ex) {
            dataSource = null;
            throw new FatalError(toString() + " : " + ex, ex);
        }
    }
}
Also used : FatalError(com.arjuna.ats.arjuna.exceptions.FatalError) HashMap(java.util.HashMap) Method(java.lang.reflect.Method) SQLException(java.sql.SQLException)

Example 2 with FatalError

use of com.arjuna.ats.arjuna.exceptions.FatalError in project narayana by jbosstm.

the class ExecProcessId method getpid.

/**
 * @return the process id. This had better be unique between processes on
 *         the same machine. If not we're in trouble!
 */
public int getpid() {
    synchronized (ExecProcessId._lock) {
        if (_pid == -1) {
            String[] cmd = null;
            File tempFile = null;
            if (System.getProperty("os.name").toLowerCase().indexOf("windows") == -1)
                cmd = new String[] { "/bin/sh", "-c", "echo $$ $PPID" };
            else {
                try {
                    // http://www.scheibli.com/projects/getpids/index.html (GPL)
                    tempFile = File.createTempFile("getpids", "ts");
                    byte[] bytes = new byte[1024];
                    int read;
                    InputStream in = ExecProcessId.class.getResourceAsStream("getpids.exe");
                    OutputStream out = new FileOutputStream(tempFile);
                    try {
                        while ((read = in.read(bytes)) != -1) out.write(bytes, 0, read);
                    } finally {
                        in.close();
                        out.close();
                    }
                    cmd = new String[] { tempFile.getAbsolutePath() };
                } catch (final Exception ex) {
                    throw new FatalError(tsLogger.i18NLogger.get_utils_ExecProcessId_2() + " " + ex, ex);
                }
            }
            if (cmd != null) {
                Process p = null;
                try {
                    p = Runtime.getRuntime().exec(cmd);
                } catch (final IOException ex) {
                    throw new FatalError(tsLogger.i18NLogger.get_utils_ExecProcessId_3() + " " + ex, ex);
                }
                ByteArrayOutputStream bstream = new ByteArrayOutputStream();
                byte[] bytes = new byte[1024];
                int read;
                try {
                    while ((read = p.getInputStream().read(bytes)) != -1) bstream.write(bytes, 0, read);
                } catch (final Exception ex) {
                    throw new FatalError(tsLogger.i18NLogger.get_utils_ExecProcessId_4() + " " + ex, ex);
                } finally {
                    try {
                        bstream.close();
                    } catch (final Exception ex) {
                        tsLogger.i18NLogger.warn_utils_ExecProcessId_5(ex);
                    }
                }
                if (tempFile != null)
                    tempFile.delete();
                StringTokenizer theTokenizer;
                try {
                    theTokenizer = new StringTokenizer(bstream.toString(StandardCharsets.UTF_8.name()));
                } catch (UnsupportedEncodingException e) {
                    tsLogger.i18NLogger.fatal_encoding_not_supported(StandardCharsets.UTF_8.name());
                    throw new IllegalStateException(tsLogger.i18NLogger.get_encoding_not_supported(StandardCharsets.UTF_8.name()));
                }
                theTokenizer.nextToken();
                String pid = theTokenizer.nextToken();
                try {
                    _pid = Integer.parseInt(pid);
                } catch (final Exception ex) {
                }
            }
        }
    }
    if (_pid == -1)
        throw new FatalError(tsLogger.i18NLogger.get_utils_ExecProcessId_1());
    return _pid;
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FatalError(com.arjuna.ats.arjuna.exceptions.FatalError) StringTokenizer(java.util.StringTokenizer) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 3 with FatalError

use of com.arjuna.ats.arjuna.exceptions.FatalError in project narayana by jbosstm.

the class ExceptionsUnitTest method test.

@Test
public void test() {
    FatalError fe = new FatalError();
    fe = new FatalError("problem");
    fe = new FatalError("problem", new NullPointerException());
    fe = new FatalError(new NullPointerException());
    ObjectStoreError os = new ObjectStoreError();
    os = new ObjectStoreError("problem");
    os = new ObjectStoreError("problem", new NullPointerException());
    os = new ObjectStoreError(new NullPointerException());
    ObjectStoreException ox = new ObjectStoreException();
    ox = new ObjectStoreException("problem");
    ox = new ObjectStoreException("problem", new NullPointerException());
    ox = new ObjectStoreException(new NullPointerException());
}
Also used : FatalError(com.arjuna.ats.arjuna.exceptions.FatalError) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) ObjectStoreError(com.arjuna.ats.arjuna.exceptions.ObjectStoreError) Test(org.junit.Test)

Example 4 with FatalError

use of com.arjuna.ats.arjuna.exceptions.FatalError in project narayana by jbosstm.

the class FileProcessId method getpid.

/**
 * @return the process id. This had better be unique between processes
 * on the same machine. If not we're in trouble!
 *
 * @since JTS 2.1.
 */
public int getpid() {
    if (FileProcessId.processId == 0) {
        synchronized (FileProcessId.lock) {
            if (FileProcessId.processId == 0) {
                int retry = 1000;
                int pid = (int) System.currentTimeMillis();
                pid = Math.abs(pid);
                /*
		     * Use the "var" directory location from the property file.
		     * If it is not set, create "./var/tmp".
		     */
                String dir = arjPropertyManager.getCoreEnvironmentBean().getVarDir();
                if (dir == null || dir.length() == 0)
                    dir = System.getProperty("user.dir") + File.separator + "var" + File.separator + "tmp";
                else
                    dir = dir + File.separator + "tmp";
                File tmpDir = new File(dir);
                if (tmpDir.isDirectory() == false && tmpDir.mkdirs() == false)
                    throw new FatalError(tsLogger.i18NLogger.get_utils_FileProcessId_1());
                for (int i = 0; i < retry; i++) {
                    try {
                        File f = new File(dir + File.separator + "pid " + pid);
                        if (f.createNewFile()) {
                            // problem if we crash?
                            f.deleteOnExit();
                            processId = pid;
                            break;
                        } else
                            pid++;
                    } catch (IOException e) {
                    }
                }
                if (processId == 0)
                    throw new FatalError(tsLogger.i18NLogger.get_utils_FileProcessId_2());
            }
        }
    }
    return processId;
}
Also used : FatalError(com.arjuna.ats.arjuna.exceptions.FatalError) IOException(java.io.IOException) File(java.io.File)

Example 5 with FatalError

use of com.arjuna.ats.arjuna.exceptions.FatalError in project narayana by jbosstm.

the class InterpositionORBInitializerImpl method pre_init.

public void pre_init(ORBInitInfo init_info) {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("InterpositionORBInitializer.pre_init ()");
    }
    /*
	 * These value should be part of the standard.
	 */
    int localSlot = init_info.allocate_slot_id();
    int receivedSlot = init_info.allocate_slot_id();
    OTSManager.setLocalSlotId(localSlot);
    OTSManager.setReceivedSlotId(receivedSlot);
    /*
	 * Get the CDR codec; used for encoding/decoding the service
	 * context and IOR components.
	 */
    Codec cdr_codec = null;
    try {
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("InterpositionORBInitializerImpl - getting reference to ENCODING_CDR_ENCAPS codec");
        }
        Encoding cdr_encoding = new Encoding(ENCODING_CDR_ENCAPS.value, (byte) 1, (byte) 2);
        cdr_codec = init_info.codec_factory().create_codec(cdr_encoding);
    } catch (UnknownEncoding ex) {
        jtsLogger.i18NLogger.warn_orbspecific_javaidl_interceptors_interposition_codecerror("InterpositionORBInitializerImpl", "ENCODING_CDR_ENCAPS", ex);
        throw new FatalError(jtsLogger.i18NLogger.get_orbspecific_javaidl_interceptors_interposition_codeccreate(), ex);
    }
    try {
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("InterpositionORBInitializerImpl - registering ClientRequestInterceptor");
        }
        ClientRequestInterceptor client_interceptor = new InterpositionClientRequestInterceptorImpl(localSlot, cdr_codec);
        init_info.add_client_request_interceptor(client_interceptor);
    } catch (DuplicateName ex) {
        jtsLogger.i18NLogger.warn_orbspecific_javaidl_interceptors_interposition_duplicatename("InterpositionORBInitializerImpl", "ClientRequestInterceptor", ex);
        throw new FatalError(jtsLogger.i18NLogger.get_orbspecific_javaidl_interceptors_interposition_cie(), ex);
    }
    try {
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("InterpositionORBInitializerImpl - registering ServerRequestInterceptor");
        }
        ServerRequestInterceptor server_interceptor = new InterpositionServerRequestInterceptorImpl(receivedSlot, cdr_codec);
        init_info.add_server_request_interceptor(server_interceptor);
    } catch (DuplicateName ex) {
        jtsLogger.i18NLogger.warn_orbspecific_javaidl_interceptors_interposition_duplicatename("InterpositionORBInitializerImpl", "ServerRequestInterceptor", ex);
        throw new FatalError(jtsLogger.i18NLogger.get_orbspecific_javaidl_interceptors_interposition_sie(), ex);
    }
}
Also used : FatalError(com.arjuna.ats.arjuna.exceptions.FatalError) Codec(org.omg.IOP.Codec) ClientRequestInterceptor(org.omg.PortableInterceptor.ClientRequestInterceptor) UnknownEncoding(org.omg.IOP.CodecFactoryPackage.UnknownEncoding) DuplicateName(org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName) Encoding(org.omg.IOP.Encoding) UnknownEncoding(org.omg.IOP.CodecFactoryPackage.UnknownEncoding) ServerRequestInterceptor(org.omg.PortableInterceptor.ServerRequestInterceptor)

Aggregations

FatalError (com.arjuna.ats.arjuna.exceptions.FatalError)19 Codec (org.omg.IOP.Codec)6 UnknownEncoding (org.omg.IOP.CodecFactoryPackage.UnknownEncoding)6 Encoding (org.omg.IOP.Encoding)6 ClientRequestInterceptor (org.omg.PortableInterceptor.ClientRequestInterceptor)6 DuplicateName (org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName)6 ServerRequestInterceptor (org.omg.PortableInterceptor.ServerRequestInterceptor)6 IOException (java.io.IOException)4 Test (org.junit.Test)3 ObjectStoreEnvironmentBean (com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean)2 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)2 File (java.io.File)2 Uid (com.arjuna.ats.arjuna.common.Uid)1 ObjectStoreError (com.arjuna.ats.arjuna.exceptions.ObjectStoreError)1 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)1 TwoPhaseVolatileStore (com.arjuna.ats.internal.arjuna.objectstore.TwoPhaseVolatileStore)1 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)1 ORB (com.arjuna.orbportability.ORB)1 RootOA (com.arjuna.orbportability.RootOA)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1