001
014
015 package com.liferay.portal.kernel.nio.intraband.welder.fifo;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019
020 import java.io.File;
021
022
025 public class FIFOUtil {
026
027 public static void createFIFO(File fifoFile) throws Exception {
028 ProcessBuilder processBuilder = new ProcessBuilder(
029 "mkfifo", fifoFile.getAbsolutePath());
030
031 Process mkfifoProcess = null;
032
033 try {
034 mkfifoProcess = processBuilder.start();
035
036 int result = mkfifoProcess.waitFor();
037
038 if (result != 0) {
039 throw new Exception(
040 "Unable to create FIFO with command \"mkfifo\", " +
041 "external process returned " + result);
042 }
043 }
044 finally {
045 if (mkfifoProcess != null) {
046 mkfifoProcess.destroy();
047 }
048 }
049 }
050
051 public static boolean isFIFOSupported() {
052 return _FIFO_SUPPORTED;
053 }
054
055 private static final boolean _FIFO_SUPPORTED;
056
057 private static final Log _log = LogFactoryUtil.getLog(FIFOUtil.class);
058
059 static {
060 boolean fifoSupport = false;
061
062 try {
063 File tempFIFOFile = new File(
064 System.getProperty("java.io.tmpdir"),
065 "temp-fifo-" + System.currentTimeMillis());
066
067 try {
068 createFIFO(tempFIFOFile);
069 }
070 finally {
071 if (!tempFIFOFile.delete()) {
072 if (tempFIFOFile.exists()) {
073 tempFIFOFile.deleteOnExit();
074 }
075 }
076 }
077
078 fifoSupport = true;
079 }
080 catch (Throwable t) {
081 if (_log.isWarnEnabled()) {
082 _log.warn("Unable to detect FIFO support", t);
083 }
084 }
085
086 _FIFO_SUPPORTED = fifoSupport;
087 }
088
089 }