com.mirth.connect.server.util.javascript.JavaScriptExecutorException: java.lang.IllegalStateException: Calling Context.exit without previous Context.enter

Mirth Project | justin arnold | 3 years ago
  1. 0

    When running a javascript reader after some point I get... [2013-07-26 08:41:47,986] ERROR (com.mirth.connect.connectors.js.JavaScriptReceiver:93): Error executing JavaScript Reader script 57c9b882-0cac-4421-a822-437b7cb4c7a6. com.mirth.connect.server.util.javascript.JavaScriptExecutorException: java.lang.IllegalStateException: Calling Context.exit without previous Context.enter at com.mirth.connect.server.util.javascript.JavaScriptUtil.execute(JavaScriptUtil.java:62) at com.mirth.connect.connectors.js.JavaScriptReceiver.poll(JavaScriptReceiver.java:91) at com.mirth.connect.donkey.server.channel.PollConnector$PollConnectorTask.run(PollConnector.java:111) at java.util.TimerThread.mainLoop(Timer.java:555) at java.util.TimerThread.run(Timer.java:505)Caused by: java.lang.IllegalStateException: Calling Context.exit without previous Context.enter at org.mozilla.javascript.Context.exit(Context.java:426) at com.mirth.connect.server.util.javascript.JavaScriptUtil.executeScript(JavaScriptUtil.java:435) at com.mirth.connect.connectors.js.JavaScriptReceiver$JavaScriptReceiverTask.call(JavaScriptReceiver.java:115) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:724) Javascript code is below, error occurs roughly right after logger.info("3.3") globalMap.put("ErrorType", ""); //importClass(java.net.java.net.InetAddress); var serverVersion = com.mirth.connect.server.controllers.DefaultConfigurationController.create().getServerVersion(); var initialChannelsExceedingQueue = new Array(); var afterSleepChannelsExceedingQueue = new Array(); //removed global variables for efficiency var queueDepthExceedThreshold = 99; //create controllers var channelController = com.mirth.connect.server.controllers.ChannelController.getInstance(); //var startStopController = com.mirth.connect.server.controllers.DefaultDonkeyEngineController.create(); var startStopController = com.mirth.connect.server.controllers.DonkeyEngineController.getInstance(); //var deployUndeployController = com.mirth.connect.server.controllers.MuleEngineController.create(); initialChannelsExceedingQueue = getInitialQueueDepth(); if (initialChannelsExceedingQueue.length == 0) { globalMap.put('exceedCount', 0); return 0; } java.lang.Thread.sleep(180000); afterSleepChannelsExceedingQueue = getQueueDepthAfterSleep(); //check to see if channel is processing queued items var totalQueueCount = 0; var queuedMessage = new Array(); for(i = 0; i < afterSleepChannelsExceedingQueue.length; i++) { //if queue has cleared remove from array if(afterSleepChannelsExceedingQueue[i][2] == 0) { afterSleepChannelsExceedingQueue.splice(i,1); } //if queue is clearing remove from array and set message detailing issue else if(afterSleepChannelsExceedingQueue[i][2] < initialChannelsExceedingQueue[i][2]) { queuedMessage.push(afterSleepChannelsExceedingQueue[i][0]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][1]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][2]); queuedMessage.push('Channel Clearing on Its Own'); initialChannelsExceedingQueue.splice(i,1); afterSleepChannelsExceedingQueue.splice(i,1); i--; } //if queuing not resolved add to count. else { totalQueueCount++; } } if (totalQueueCount == 0) { globalMap.put('exceedCount', queuedMessage.length); globalMap.put('queuedMessage', queuedMessage); return queuedMessage.length; } channelArray = new Array(); for(i = 0; i < initialChannelsExceedingQueue.length; i++) { if(initialChannelsExceedingQueue[i][1].substring(0,1) == '2') { //stop channel startStopController.stopChannel(initialChannelsExceedingQueue[i][0]); //wait for channel to stop //while(GetChannelState(initialChannelsExceedingQueue[i][0],initialChannelsExceedingQueue[i][4]) != 'Disconnected'); //{ java.lang.Thread.sleep(10000); //} //start channel startStopController.startChannel(initialChannelsExceedingQueue[i][0]); //wait for channel to start /*var tries = 0; while(GetChannelState(initialChannelsExceedingQueue[i][0],initialChannelsExceedingQueue[i][4]) =='Disconnected' && tries < 5) { java.lang.Thread.sleep(10000); tries++; } if(GetChannelState(initialChannelsExceedingQueue[i][0],initialChannelsExceedingQueue[i][4]) == 'Disconnected') { channelArray.push(initialChannelsExceedingQueue[i][0]); }*/ } else { queuedMessage.push(afterSleepChannelsExceedingQueue[i][0]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][1]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][2]); queuedMessage.push('Channel Is Not an Outbound Channel. Must Fix Outbound Channel'); initialChannelsExceedingQueue.splice(i,1); afterSleepChannelsExceedingQueue.splice(i,1); i--; } } redeployChannels(channelArray); java.lang.Thread.sleep(20000); if(initialChannelsExceedingQueue.length == 0) { globalMap.put('exceedCount', queuedMessage.length); globalMap.put('queuedMessage', queuedMessage); return queuedMessage.length; } //allow channel to start processing java.lang.Thread.sleep(30000); afterSleepChannelsExceedingQueue = getQueueDepthAfterSleep(); //check to see if issue resolves with starting and stopping channel channelArray = new Array(); for(i = 0; i < afterSleepChannelsExceedingQueue.length; i++) { //if queue has cleared remove from array if(afterSleepChannelsExceedingQueue[i][2] == 0) { queuedMessage.push(afterSleepChannelsExceedingQueue[i][0]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][1]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][2]); queuedMessage.push('Issue resolved by stopping and starting channel'); initialChannelsExceedingQueue.splice(i,1); afterSleepChannelsExceedingQueue.splice(i,1); i--; } //if queue is clearing remove from array and set message detailing issue // +5 is to account for message that error off because of starting and stopping else if(afterSleepChannelsExceedingQueue[i][2] + 5 < initialChannelsExceedingQueue[i][2]) { queuedMessage.push(afterSleepChannelsExceedingQueue[i][0]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][1]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][2]); queuedMessage.push('Channel Clearing After Stopping and Starting'); initialChannelsExceedingQueue.splice(i,1); afterSleepChannelsExceedingQueue.splice(i,1); i--; } //if queuing not resolved add to array to redeploy. else { //stop channel. Channel must be stopped before redepoying on version 2.2 startStopController.stopChannel(initialChannelsExceedingQueue[i][0]); //wait for channel to stop //while(GetChannelState(initialChannelsExceedingQueue[i][0],initialChannelsExceedingQueue[i][4]) != 'Disconnected'); //{ java.lang.Thread.sleep(10000); //} channelArray.push(initialChannelsExceedingQueue[i][0]); } } var redeployStatus = redeployChannels(channelArray); java.lang.Thread.sleep(30000); if(initialChannelsExceedingQueue.length == 0) { globalMap.put('exceedCount', queuedMessage.length); globalMap.put('queuedMessage', queuedMessage); return queuedMessage.length; } afterSleepChannelsExceedingQueue = getQueueDepthAfterSleep(); for(i = 0; i < afterSleepChannelsExceedingQueue.length; i++) { //if queue has cleared remove from array if(redeployStatus[afterSleepChannelsExceedingQueue[i][0]] != null) { queuedMessage.push(afterSleepChannelsExceedingQueue[i][0]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][1]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][2]); queuedMessage.push(redeployStatus[afterSleepChannelsExceedingQueue[i][0]]); } else if(afterSleepChannelsExceedingQueue[i][2] == 0) { queuedMessage.push(afterSleepChannelsExceedingQueue[i][0]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][1]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][2]); queuedMessage.push('Issue resolved by redeploying channel'); } //if queue is clearing remove from array and set message detailing issue // +5 is to account for message that error off because of redeploying else if(afterSleepChannelsExceedingQueue[i][2] + 5 < initialChannelsExceedingQueue[i][2]) { queuedMessage.push(afterSleepChannelsExceedingQueue[i][0]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][1]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][2]); queuedMessage.push('Redeploying Channel Started Process'); } else { var connectionStatuses = testConnection(afterSleepChannelsExceedingQueue[i][0], afterSleepChannelsExceedingQueue[i][4]); for(j = 0; j < connectionStatuses.length; j = j+2) { queuedMessage.push(afterSleepChannelsExceedingQueue[i][0] + ' ' + connectionStatuses[j]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][1]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][2]); queuedMessage.push(connectionStatuses[j + 1]); } } } globalMap.put('queuedMessage', queuedMessage); globalMap.put('exceedCount', queuedMessage.length); logger.info("made it to end:" + queuedMessage.length); return queuedMessage.length; function getInitialQueueDepth() { var dbUri = 'jdbc:postgresql://localhost:5432/'; var mirthdb_name = globalMap.get('mirthdb_name'); var mirthdb_user = globalMap.get('mirthdb_user'); var mirthdb_password = globalMap.get('mirthdb_password'); var channellist = "SELECT local_channel_id, name, id FROM channel, d_channels WHERE channel_id = id AND " + "channel LIKE '%description>%<enabled>true</enabled>%<lastModified%' AND substr(name,1,1) in ('0','1','2');"; var dbConn = DatabaseConnectionFactory.createDatabaseConnection("org.postgresql.Driver", dbUri + mirthdb_name, mirthdb_user, mirthdb_password); var result = dbConn.executeCachedQuery(channellist); var rows = new Array(); var columns = null; while(result.next()) { var local_channel_id = result.getString(1); var channel_name = result.getString(2); var channel_id = result.getString(3); var result2 = dbConn.executeCachedQuery("SELECT count(*) AS cnt, MAX(received_date) FROM d_mm" + local_channel_id + " WHERE status = 'Q' HAVING count(*) > " + queueDepthExceedThreshold + ";"); if(result2.next()) { columns = [channel_id, channel_name, result2.getString(1), result2.getString(2), local_channel_id]; rows.push(columns); } } dbConn.close(); return rows; } function getQueueDepthAfterSleep() { var dbUri = 'jdbc:postgresql://localhost:5432/'; var mirthdb_name = globalMap.get('mirthdb_name'); var mirthdb_user = globalMap.get('mirthdb_user'); var mirthdb_password = globalMap.get('mirthdb_password'); /*var resultQuery = "SELECT c.id, c.name, CASE WHEN t.cnt IS NULL THEN 0 ELSE t.cnt END, max FROM channel c " + "LEFT OUTER JOIN (SELECT COUNT(*) AS cnt, m.channel_id, MAX(m.date_created) as max " + "FROM MESSAGE m WHERE m.status = 'QUEUED' GROUP BY m.channel_id, m.status) t " + "ON (t.channel_id = c.id) WHERE c.id in ("; for(i = 0; i < initialChannelsExceedingQueue.length; i++) { resultQuery += "'" + initialChannelsExceedingQueue[i][0] + "'"; if(i != initialChannelsExceedingQueue.length -1) { resultQuery += ", "; } } resultQuery += ") ORDER BY c.name";*/ var dbConn = DatabaseConnectionFactory.createDatabaseConnection("org.postgresql.Driver", dbUri + mirthdb_name, mirthdb_user, mirthdb_password); var rows = new Array(); var columns = null; for(i = 0; i < initialChannelsExceedingQueue.length; i++) { var result = dbConn.executeCachedQuery("SELECT count(*) AS cnt, MAX(received_date) FROM d_mm" + initialChannelsExceedingQueue[i][4] + " WHERE status = 'Q';"); if(result.next()) { columns = [initialChannelsExceedingQueue[i][0], initialChannelsExceedingQueue[i][1], result.getString(1), result.getString(2),initialChannelsExceedingQueue[i][4]]; rows.push(columns); } } /*var dbConn = DatabaseConnectionFactory.createDatabaseConnection("org.postgresql.Driver", dbUri + mirthdb_name, mirthdb_user, mirthdb_password); var result = dbConn.executeCachedQuery(resultQuery); dbConn.close(); var rows = new Array(); var columns = null; while (result.next()){ columns = [result.getString(1), result.getString(2), result.getString(3), result.getString(4)]; rows.push(columns); }*/ return rows; } function GetChannelState(channel_id, local_channel_id) { var controller = com.mirth.connect.server.controllers.DefaultExtensionController.create(); var monitor = controller.getServicePlugins().get(com.mirth.connect.plugins.dashboardstatus.DashboardConnectorStatusMonitor.PLUGINPOINT); var states = monitor.invoke('getStates',null,null); for each (key in states.keySet().toArray()) { logger.info(key); //if(key != 'MessageSink_source_connector' && key.substring(0,43) == channel_id + '_source') if(key != 'MessageSink_source_connector' && key == channel_id + '_0')//' + local_channel_id) { channel_id = key; } } logger.info("end GetChannelState"); var status = states.get(channel_id)[1]; logger.info(status); return status; } function redeployChannels(channelArray) { var redeployArray = new Array(); var allUndeployed = false; var allDeployed = false; var deployChannelArray = new Array; var undeployChannelList = ''; var channelStatus = new Array(); var undeployedCheck = 0; var undeployAttempts = 0; var deployedCheck = 0; var deployAttempts = 0; var result = 'Success'; var deployErrors = new Array(); for(i = 0; i < channelArray.length; i++) { redeployArray.push(channelArray[i]); } undeployChannelList = java.util.Arrays.asList(redeployArray); while(undeployAttempts < 3) { //deployUndeployController.undeployChannels(undeployChannelList, for(j = 0; j < redeployArray.length; j++) { logger.info("undeploy channel:" + redeployArray[j]); startStopController.undeployChannel(redeployArray[j], com.mirth.connect.model.ServerEventContext.SYSTEM_USER_EVENT_CONTEXT); } undeployedCheck = 0; while(undeployedCheck < 3) { var channelStatuses = com.mirth.connect.server.controllers.DonkeyEngineController.getInstance().getChannelStatusList().toArray(); allUndeployed = true; for each(channel in channelStatuses) { channelStatus[channel.channelId] = channel.state; } for (i = 0; i < redeployArray.length; i++) { if(channelStatus[redeployArray[i]] == 'STARTED' || channelStatus[redeployArray[i]] == 'STOPPED') { allUndeployed = false; if(deployErrors[redeployArray[i]] == null) { deployErrors[redeployArray[i]] = 'Unable to Undeploy Channel'; } } else { if(deployErrors[redeployArray[i]]) { deployErrors.splice(redeployArray[i],1); } } } if(allUndeployed) { undeployedCheck = 3; } else { java.lang.Thread.sleep(5000); undeployedCheck++; } } if(allUndeployed) { undeployAttempts = 3; } else { undeployAttempts++; } } logger.info("got here 1"); for(i = 0; i < redeployArray.length; i++) { if(deployErrors[redeployArray[i]] == 'Unable to Undeploy Channel') { redeployArray.splice(i,1); i--; } } logger.info("got here 2"); java.lang.Thread.sleep(5000); for (i = 0; i < redeployArray.length; i++) { if(serverVersion == '2.1.1.5490') { var channel = channelController.getCachedChannelById(redeployArray[i]); deployChannelArray.push(channel); } else { deployChannelArray.push(redeployArray[i]); } } logger.info("got here 3"); while(redeployArray.length > 0 && deployAttempts < 3) { var deployChannelList = java.util.Arrays.asList(deployChannelArray); //deployUndeployController.deployChannels(deployChannelList, for(j = 0; j < deployChannelArray.length; j++) { logger.info("got here 3.1"); startStopController.deployChannel(deployChannelArray[j], com.mirth.connect.model.ServerEventContext.SYSTEM_USER_EVENT_CONTEXT); } logger.info("got here 3.2"); while(deployedCheck < 3) { var channelStatuses = com.mirth.connect.server.controllers.DonkeyEngineController.getInstance().getChannelStatusList().toArray(); allDeployed = true; logger.info("got here 3.3"); /*for each(channel in channelStatuses) { logger.info("got here 3.3.0"); channelStatus[channel.channelId] = channel.state; }*/ for(k = 0; k < channelStatuses.length; k++)//channel in channelStatuses) { logger.info("got here 3.3.0"); channelStatus[channelStatuses[k].channelId] = channelStatuses[k].state; } logger.info("got here 3.3.1"); for (i = 0; i < redeployArray.length; i++) { logger.info("got here 3.3.2"); if(channelStatus[redeployArray[i]] != 'STARTED') { allDeployed = false; if(deployErrors[redeployArray[i]] == null) { deployErrors[redeployArray[i]] = 'Unable to Deploy Channel'; } else { if(deployErrors[redeployArray[i]]) { deployErrors.splice(redeployArray[i],1); } } } logger.info("got here 3.3.3"); if(allDeployed) { deployedCheck = 3; } else { logger.info("got here 3.4"); java.lang.Thread.sleep(5000); deployedCheck++; } } } logger.info("got here 3.5"); if(allDeployed) { deployAttempts = 3; } else { deployAttempts++; } } logger.info("got here 4"); for(i = 0; i < redeployArray.length; i++) { if(deployErrors[redeployArray[i]] == 'Unable to Deploy Channel') { redeployArray.splice(i,1); i--; } } logger.info("at end of redeployChannels"); return deployErrors; } function testConnection(queuedChannel, localChannelId) { var ports = new Array(); var ips = new Array(); for each (destination in com.mirth.connect.server.controllers.DefaultChannelController.create().getDeployedChannelById(queuedChannel).getDestinationConnectors().toArray()) { ports[destination.getName()] = destination.getProperties().getProperty('port'); ips[destination.getName()] = destination.getProperties().getProperty('host'); } var dbUri = 'jdbc:postgresql://localhost:5432/'; var mirthdb_name = globalMap.get('mirthdb_name'); var mirthdb_user = globalMap.get('mirthdb_user'); var mirthdb_password = globalMap.get('mirthdb_password'); /*var resultQuery = "SELECT DISTINCT CONNECTOR_NAME FROM MESSAGE WHERE CHANNEL_ID = '" + queuedChannel + "' " + "AND STATUS = 'QUEUED' AND CONNECTOR_NAME != 'Source'";*/ var resultQuery = "SELECT DISTINCT CONNECTOR_NAME FROM d_mm" + localChannelId + " WHERE " + "STATUS = 'Q' AND CONNECTOR_NAME != 'Source'"; var dbConn = DatabaseConnectionFactory.createDatabaseConnection("org.postgresql.Driver", dbUri + mirthdb_name, mirthdb_user, mirthdb_password); var result = dbConn.executeCachedQuery(resultQuery); dbConn.close(); var connectors = new Array(); var connectionStatus = new Array(); while (result.next()) { if (ips[result.getString(1)]) { var destination = result.getString(1) var hostLine = ips[destination]; var portLine = ports[destination]; if(hostLine.substring(0,2) == '${') { hostLine = globalMap.get(hostLine.substring(2, hostLine.length() - 1)); } if(portLine.substring(0,2) == '${') { portLine = globalMap.get(portLine.substring(2, portLine.length() - 1)); } if(portLine != null) { if(com.mirth.connect.server.util.ConnectorUtil.testConnection(hostLine, portLine, 5000).getType().toString() != 'FAILURE' && com.mirth.connect.server.util.ConnectorUtil.testConnection(hostLine, portLine, 5000).getType().toString() != 'TIME_OUT') { connectionStatus.push(destination); connectionStatus.push('Can Connect To Ports for ' + destination + ' Further research is required'); } else if(java.net.InetAddress.getByName(hostLine).isReachable(10000)) { connectionStatus.push(destination); connectionStatus.push('Can Ping Site Have Ports Bounced for ' + destination); } else { var solution = getErrorSolution("Cannot reach destination"); connectionStatus.push(destination); //connectionStatus.push('Can Not Ping Site Call IS Direct to Insure Server is up for ' + destination); connectionStatus.push(solution + destination); globalMap.put("ErrorType", "Cannot reach destination"); } } else { connectionStatus.push(destination); connectionStatus.push('Unable to test connection for ' + destination); } } } logger.info("at end of test connection"); return connectionStatus; }

    Mirth Project | 3 years ago | justin arnold
    java.lang.IllegalStateException: Calling Context.exit without previous Context.enter
  2. 0

    When running a javascript reader after some point I get... [2013-07-26 08:41:47,986] ERROR (com.mirth.connect.connectors.js.JavaScriptReceiver:93): Error executing JavaScript Reader script 57c9b882-0cac-4421-a822-437b7cb4c7a6. com.mirth.connect.server.util.javascript.JavaScriptExecutorException: java.lang.IllegalStateException: Calling Context.exit without previous Context.enter at com.mirth.connect.server.util.javascript.JavaScriptUtil.execute(JavaScriptUtil.java:62) at com.mirth.connect.connectors.js.JavaScriptReceiver.poll(JavaScriptReceiver.java:91) at com.mirth.connect.donkey.server.channel.PollConnector$PollConnectorTask.run(PollConnector.java:111) at java.util.TimerThread.mainLoop(Timer.java:555) at java.util.TimerThread.run(Timer.java:505)Caused by: java.lang.IllegalStateException: Calling Context.exit without previous Context.enter at org.mozilla.javascript.Context.exit(Context.java:426) at com.mirth.connect.server.util.javascript.JavaScriptUtil.executeScript(JavaScriptUtil.java:435) at com.mirth.connect.connectors.js.JavaScriptReceiver$JavaScriptReceiverTask.call(JavaScriptReceiver.java:115) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:724) Javascript code is below, error occurs roughly right after logger.info("3.3") globalMap.put("ErrorType", ""); //importClass(java.net.java.net.InetAddress); var serverVersion = com.mirth.connect.server.controllers.DefaultConfigurationController.create().getServerVersion(); var initialChannelsExceedingQueue = new Array(); var afterSleepChannelsExceedingQueue = new Array(); //removed global variables for efficiency var queueDepthExceedThreshold = 99; //create controllers var channelController = com.mirth.connect.server.controllers.ChannelController.getInstance(); //var startStopController = com.mirth.connect.server.controllers.DefaultDonkeyEngineController.create(); var startStopController = com.mirth.connect.server.controllers.DonkeyEngineController.getInstance(); //var deployUndeployController = com.mirth.connect.server.controllers.MuleEngineController.create(); initialChannelsExceedingQueue = getInitialQueueDepth(); if (initialChannelsExceedingQueue.length == 0) { globalMap.put('exceedCount', 0); return 0; } java.lang.Thread.sleep(180000); afterSleepChannelsExceedingQueue = getQueueDepthAfterSleep(); //check to see if channel is processing queued items var totalQueueCount = 0; var queuedMessage = new Array(); for(i = 0; i < afterSleepChannelsExceedingQueue.length; i++) { //if queue has cleared remove from array if(afterSleepChannelsExceedingQueue[i][2] == 0) { afterSleepChannelsExceedingQueue.splice(i,1); } //if queue is clearing remove from array and set message detailing issue else if(afterSleepChannelsExceedingQueue[i][2] < initialChannelsExceedingQueue[i][2]) { queuedMessage.push(afterSleepChannelsExceedingQueue[i][0]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][1]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][2]); queuedMessage.push('Channel Clearing on Its Own'); initialChannelsExceedingQueue.splice(i,1); afterSleepChannelsExceedingQueue.splice(i,1); i--; } //if queuing not resolved add to count. else { totalQueueCount++; } } if (totalQueueCount == 0) { globalMap.put('exceedCount', queuedMessage.length); globalMap.put('queuedMessage', queuedMessage); return queuedMessage.length; } channelArray = new Array(); for(i = 0; i < initialChannelsExceedingQueue.length; i++) { if(initialChannelsExceedingQueue[i][1].substring(0,1) == '2') { //stop channel startStopController.stopChannel(initialChannelsExceedingQueue[i][0]); //wait for channel to stop //while(GetChannelState(initialChannelsExceedingQueue[i][0],initialChannelsExceedingQueue[i][4]) != 'Disconnected'); //{ java.lang.Thread.sleep(10000); //} //start channel startStopController.startChannel(initialChannelsExceedingQueue[i][0]); //wait for channel to start /*var tries = 0; while(GetChannelState(initialChannelsExceedingQueue[i][0],initialChannelsExceedingQueue[i][4]) =='Disconnected' && tries < 5) { java.lang.Thread.sleep(10000); tries++; } if(GetChannelState(initialChannelsExceedingQueue[i][0],initialChannelsExceedingQueue[i][4]) == 'Disconnected') { channelArray.push(initialChannelsExceedingQueue[i][0]); }*/ } else { queuedMessage.push(afterSleepChannelsExceedingQueue[i][0]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][1]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][2]); queuedMessage.push('Channel Is Not an Outbound Channel. Must Fix Outbound Channel'); initialChannelsExceedingQueue.splice(i,1); afterSleepChannelsExceedingQueue.splice(i,1); i--; } } redeployChannels(channelArray); java.lang.Thread.sleep(20000); if(initialChannelsExceedingQueue.length == 0) { globalMap.put('exceedCount', queuedMessage.length); globalMap.put('queuedMessage', queuedMessage); return queuedMessage.length; } //allow channel to start processing java.lang.Thread.sleep(30000); afterSleepChannelsExceedingQueue = getQueueDepthAfterSleep(); //check to see if issue resolves with starting and stopping channel channelArray = new Array(); for(i = 0; i < afterSleepChannelsExceedingQueue.length; i++) { //if queue has cleared remove from array if(afterSleepChannelsExceedingQueue[i][2] == 0) { queuedMessage.push(afterSleepChannelsExceedingQueue[i][0]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][1]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][2]); queuedMessage.push('Issue resolved by stopping and starting channel'); initialChannelsExceedingQueue.splice(i,1); afterSleepChannelsExceedingQueue.splice(i,1); i--; } //if queue is clearing remove from array and set message detailing issue // +5 is to account for message that error off because of starting and stopping else if(afterSleepChannelsExceedingQueue[i][2] + 5 < initialChannelsExceedingQueue[i][2]) { queuedMessage.push(afterSleepChannelsExceedingQueue[i][0]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][1]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][2]); queuedMessage.push('Channel Clearing After Stopping and Starting'); initialChannelsExceedingQueue.splice(i,1); afterSleepChannelsExceedingQueue.splice(i,1); i--; } //if queuing not resolved add to array to redeploy. else { //stop channel. Channel must be stopped before redepoying on version 2.2 startStopController.stopChannel(initialChannelsExceedingQueue[i][0]); //wait for channel to stop //while(GetChannelState(initialChannelsExceedingQueue[i][0],initialChannelsExceedingQueue[i][4]) != 'Disconnected'); //{ java.lang.Thread.sleep(10000); //} channelArray.push(initialChannelsExceedingQueue[i][0]); } } var redeployStatus = redeployChannels(channelArray); java.lang.Thread.sleep(30000); if(initialChannelsExceedingQueue.length == 0) { globalMap.put('exceedCount', queuedMessage.length); globalMap.put('queuedMessage', queuedMessage); return queuedMessage.length; } afterSleepChannelsExceedingQueue = getQueueDepthAfterSleep(); for(i = 0; i < afterSleepChannelsExceedingQueue.length; i++) { //if queue has cleared remove from array if(redeployStatus[afterSleepChannelsExceedingQueue[i][0]] != null) { queuedMessage.push(afterSleepChannelsExceedingQueue[i][0]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][1]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][2]); queuedMessage.push(redeployStatus[afterSleepChannelsExceedingQueue[i][0]]); } else if(afterSleepChannelsExceedingQueue[i][2] == 0) { queuedMessage.push(afterSleepChannelsExceedingQueue[i][0]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][1]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][2]); queuedMessage.push('Issue resolved by redeploying channel'); } //if queue is clearing remove from array and set message detailing issue // +5 is to account for message that error off because of redeploying else if(afterSleepChannelsExceedingQueue[i][2] + 5 < initialChannelsExceedingQueue[i][2]) { queuedMessage.push(afterSleepChannelsExceedingQueue[i][0]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][1]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][2]); queuedMessage.push('Redeploying Channel Started Process'); } else { var connectionStatuses = testConnection(afterSleepChannelsExceedingQueue[i][0], afterSleepChannelsExceedingQueue[i][4]); for(j = 0; j < connectionStatuses.length; j = j+2) { queuedMessage.push(afterSleepChannelsExceedingQueue[i][0] + ' ' + connectionStatuses[j]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][1]); queuedMessage.push(afterSleepChannelsExceedingQueue[i][2]); queuedMessage.push(connectionStatuses[j + 1]); } } } globalMap.put('queuedMessage', queuedMessage); globalMap.put('exceedCount', queuedMessage.length); logger.info("made it to end:" + queuedMessage.length); return queuedMessage.length; function getInitialQueueDepth() { var dbUri = 'jdbc:postgresql://localhost:5432/'; var mirthdb_name = globalMap.get('mirthdb_name'); var mirthdb_user = globalMap.get('mirthdb_user'); var mirthdb_password = globalMap.get('mirthdb_password'); var channellist = "SELECT local_channel_id, name, id FROM channel, d_channels WHERE channel_id = id AND " + "channel LIKE '%description>%<enabled>true</enabled>%<lastModified%' AND substr(name,1,1) in ('0','1','2');"; var dbConn = DatabaseConnectionFactory.createDatabaseConnection("org.postgresql.Driver", dbUri + mirthdb_name, mirthdb_user, mirthdb_password); var result = dbConn.executeCachedQuery(channellist); var rows = new Array(); var columns = null; while(result.next()) { var local_channel_id = result.getString(1); var channel_name = result.getString(2); var channel_id = result.getString(3); var result2 = dbConn.executeCachedQuery("SELECT count(*) AS cnt, MAX(received_date) FROM d_mm" + local_channel_id + " WHERE status = 'Q' HAVING count(*) > " + queueDepthExceedThreshold + ";"); if(result2.next()) { columns = [channel_id, channel_name, result2.getString(1), result2.getString(2), local_channel_id]; rows.push(columns); } } dbConn.close(); return rows; } function getQueueDepthAfterSleep() { var dbUri = 'jdbc:postgresql://localhost:5432/'; var mirthdb_name = globalMap.get('mirthdb_name'); var mirthdb_user = globalMap.get('mirthdb_user'); var mirthdb_password = globalMap.get('mirthdb_password'); /*var resultQuery = "SELECT c.id, c.name, CASE WHEN t.cnt IS NULL THEN 0 ELSE t.cnt END, max FROM channel c " + "LEFT OUTER JOIN (SELECT COUNT(*) AS cnt, m.channel_id, MAX(m.date_created) as max " + "FROM MESSAGE m WHERE m.status = 'QUEUED' GROUP BY m.channel_id, m.status) t " + "ON (t.channel_id = c.id) WHERE c.id in ("; for(i = 0; i < initialChannelsExceedingQueue.length; i++) { resultQuery += "'" + initialChannelsExceedingQueue[i][0] + "'"; if(i != initialChannelsExceedingQueue.length -1) { resultQuery += ", "; } } resultQuery += ") ORDER BY c.name";*/ var dbConn = DatabaseConnectionFactory.createDatabaseConnection("org.postgresql.Driver", dbUri + mirthdb_name, mirthdb_user, mirthdb_password); var rows = new Array(); var columns = null; for(i = 0; i < initialChannelsExceedingQueue.length; i++) { var result = dbConn.executeCachedQuery("SELECT count(*) AS cnt, MAX(received_date) FROM d_mm" + initialChannelsExceedingQueue[i][4] + " WHERE status = 'Q';"); if(result.next()) { columns = [initialChannelsExceedingQueue[i][0], initialChannelsExceedingQueue[i][1], result.getString(1), result.getString(2),initialChannelsExceedingQueue[i][4]]; rows.push(columns); } } /*var dbConn = DatabaseConnectionFactory.createDatabaseConnection("org.postgresql.Driver", dbUri + mirthdb_name, mirthdb_user, mirthdb_password); var result = dbConn.executeCachedQuery(resultQuery); dbConn.close(); var rows = new Array(); var columns = null; while (result.next()){ columns = [result.getString(1), result.getString(2), result.getString(3), result.getString(4)]; rows.push(columns); }*/ return rows; } function GetChannelState(channel_id, local_channel_id) { var controller = com.mirth.connect.server.controllers.DefaultExtensionController.create(); var monitor = controller.getServicePlugins().get(com.mirth.connect.plugins.dashboardstatus.DashboardConnectorStatusMonitor.PLUGINPOINT); var states = monitor.invoke('getStates',null,null); for each (key in states.keySet().toArray()) { logger.info(key); //if(key != 'MessageSink_source_connector' && key.substring(0,43) == channel_id + '_source') if(key != 'MessageSink_source_connector' && key == channel_id + '_0')//' + local_channel_id) { channel_id = key; } } logger.info("end GetChannelState"); var status = states.get(channel_id)[1]; logger.info(status); return status; } function redeployChannels(channelArray) { var redeployArray = new Array(); var allUndeployed = false; var allDeployed = false; var deployChannelArray = new Array; var undeployChannelList = ''; var channelStatus = new Array(); var undeployedCheck = 0; var undeployAttempts = 0; var deployedCheck = 0; var deployAttempts = 0; var result = 'Success'; var deployErrors = new Array(); for(i = 0; i < channelArray.length; i++) { redeployArray.push(channelArray[i]); } undeployChannelList = java.util.Arrays.asList(redeployArray); while(undeployAttempts < 3) { //deployUndeployController.undeployChannels(undeployChannelList, for(j = 0; j < redeployArray.length; j++) { logger.info("undeploy channel:" + redeployArray[j]); startStopController.undeployChannel(redeployArray[j], com.mirth.connect.model.ServerEventContext.SYSTEM_USER_EVENT_CONTEXT); } undeployedCheck = 0; while(undeployedCheck < 3) { var channelStatuses = com.mirth.connect.server.controllers.DonkeyEngineController.getInstance().getChannelStatusList().toArray(); allUndeployed = true; for each(channel in channelStatuses) { channelStatus[channel.channelId] = channel.state; } for (i = 0; i < redeployArray.length; i++) { if(channelStatus[redeployArray[i]] == 'STARTED' || channelStatus[redeployArray[i]] == 'STOPPED') { allUndeployed = false; if(deployErrors[redeployArray[i]] == null) { deployErrors[redeployArray[i]] = 'Unable to Undeploy Channel'; } } else { if(deployErrors[redeployArray[i]]) { deployErrors.splice(redeployArray[i],1); } } } if(allUndeployed) { undeployedCheck = 3; } else { java.lang.Thread.sleep(5000); undeployedCheck++; } } if(allUndeployed) { undeployAttempts = 3; } else { undeployAttempts++; } } logger.info("got here 1"); for(i = 0; i < redeployArray.length; i++) { if(deployErrors[redeployArray[i]] == 'Unable to Undeploy Channel') { redeployArray.splice(i,1); i--; } } logger.info("got here 2"); java.lang.Thread.sleep(5000); for (i = 0; i < redeployArray.length; i++) { if(serverVersion == '2.1.1.5490') { var channel = channelController.getCachedChannelById(redeployArray[i]); deployChannelArray.push(channel); } else { deployChannelArray.push(redeployArray[i]); } } logger.info("got here 3"); while(redeployArray.length > 0 && deployAttempts < 3) { var deployChannelList = java.util.Arrays.asList(deployChannelArray); //deployUndeployController.deployChannels(deployChannelList, for(j = 0; j < deployChannelArray.length; j++) { logger.info("got here 3.1"); startStopController.deployChannel(deployChannelArray[j], com.mirth.connect.model.ServerEventContext.SYSTEM_USER_EVENT_CONTEXT); } logger.info("got here 3.2"); while(deployedCheck < 3) { var channelStatuses = com.mirth.connect.server.controllers.DonkeyEngineController.getInstance().getChannelStatusList().toArray(); allDeployed = true; logger.info("got here 3.3"); /*for each(channel in channelStatuses) { logger.info("got here 3.3.0"); channelStatus[channel.channelId] = channel.state; }*/ for(k = 0; k < channelStatuses.length; k++)//channel in channelStatuses) { logger.info("got here 3.3.0"); channelStatus[channelStatuses[k].channelId] = channelStatuses[k].state; } logger.info("got here 3.3.1"); for (i = 0; i < redeployArray.length; i++) { logger.info("got here 3.3.2"); if(channelStatus[redeployArray[i]] != 'STARTED') { allDeployed = false; if(deployErrors[redeployArray[i]] == null) { deployErrors[redeployArray[i]] = 'Unable to Deploy Channel'; } else { if(deployErrors[redeployArray[i]]) { deployErrors.splice(redeployArray[i],1); } } } logger.info("got here 3.3.3"); if(allDeployed) { deployedCheck = 3; } else { logger.info("got here 3.4"); java.lang.Thread.sleep(5000); deployedCheck++; } } } logger.info("got here 3.5"); if(allDeployed) { deployAttempts = 3; } else { deployAttempts++; } } logger.info("got here 4"); for(i = 0; i < redeployArray.length; i++) { if(deployErrors[redeployArray[i]] == 'Unable to Deploy Channel') { redeployArray.splice(i,1); i--; } } logger.info("at end of redeployChannels"); return deployErrors; } function testConnection(queuedChannel, localChannelId) { var ports = new Array(); var ips = new Array(); for each (destination in com.mirth.connect.server.controllers.DefaultChannelController.create().getDeployedChannelById(queuedChannel).getDestinationConnectors().toArray()) { ports[destination.getName()] = destination.getProperties().getProperty('port'); ips[destination.getName()] = destination.getProperties().getProperty('host'); } var dbUri = 'jdbc:postgresql://localhost:5432/'; var mirthdb_name = globalMap.get('mirthdb_name'); var mirthdb_user = globalMap.get('mirthdb_user'); var mirthdb_password = globalMap.get('mirthdb_password'); /*var resultQuery = "SELECT DISTINCT CONNECTOR_NAME FROM MESSAGE WHERE CHANNEL_ID = '" + queuedChannel + "' " + "AND STATUS = 'QUEUED' AND CONNECTOR_NAME != 'Source'";*/ var resultQuery = "SELECT DISTINCT CONNECTOR_NAME FROM d_mm" + localChannelId + " WHERE " + "STATUS = 'Q' AND CONNECTOR_NAME != 'Source'"; var dbConn = DatabaseConnectionFactory.createDatabaseConnection("org.postgresql.Driver", dbUri + mirthdb_name, mirthdb_user, mirthdb_password); var result = dbConn.executeCachedQuery(resultQuery); dbConn.close(); var connectors = new Array(); var connectionStatus = new Array(); while (result.next()) { if (ips[result.getString(1)]) { var destination = result.getString(1) var hostLine = ips[destination]; var portLine = ports[destination]; if(hostLine.substring(0,2) == '${') { hostLine = globalMap.get(hostLine.substring(2, hostLine.length() - 1)); } if(portLine.substring(0,2) == '${') { portLine = globalMap.get(portLine.substring(2, portLine.length() - 1)); } if(portLine != null) { if(com.mirth.connect.server.util.ConnectorUtil.testConnection(hostLine, portLine, 5000).getType().toString() != 'FAILURE' && com.mirth.connect.server.util.ConnectorUtil.testConnection(hostLine, portLine, 5000).getType().toString() != 'TIME_OUT') { connectionStatus.push(destination); connectionStatus.push('Can Connect To Ports for ' + destination + ' Further research is required'); } else if(java.net.InetAddress.getByName(hostLine).isReachable(10000)) { connectionStatus.push(destination); connectionStatus.push('Can Ping Site Have Ports Bounced for ' + destination); } else { var solution = getErrorSolution("Cannot reach destination"); connectionStatus.push(destination); //connectionStatus.push('Can Not Ping Site Call IS Direct to Insure Server is up for ' + destination); connectionStatus.push(solution + destination); globalMap.put("ErrorType", "Cannot reach destination"); } } else { connectionStatus.push(destination); connectionStatus.push('Unable to test connection for ' + destination); } } } logger.info("at end of test connection"); return connectionStatus; }

    Mirth Project | 3 years ago | justin arnold
    com.mirth.connect.server.util.javascript.JavaScriptExecutorException: java.lang.IllegalStateException: Calling Context.exit without previous Context.enter
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Illegal state exceptions (iscsi)

    GitHub | 6 years ago | ldriscoll
    java.lang.IllegalStateException: Calling Context.exit without previous Context.enter
  5. 0

    javascript bug in 3.1 [Archive] - Pentaho Community Forums

    pentaho.com | 6 months ago
    java.lang.IllegalStateException: Calling Context.exit without previous Context.enter

    1 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalStateException

      Calling Context.exit without previous Context.enter

      at org.mozilla.javascript.Context.exit()
    2. Rhino
      Context.exit
      1. org.mozilla.javascript.Context.exit(Context.java:426)
      1 frame
    3. com.mirth.connect
      JavaScriptReceiver$JavaScriptReceiverTask.call
      1. com.mirth.connect.server.util.javascript.JavaScriptUtil.executeScript(JavaScriptUtil.java:435)
      2. com.mirth.connect.connectors.js.JavaScriptReceiver$JavaScriptReceiverTask.call(JavaScriptReceiver.java:115)
      2 frames
    4. Java RT
      Thread.run
      1. java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      2. java.util.concurrent.FutureTask.run(FutureTask.java:166)
      3. java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      4. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      5. java.lang.Thread.run(Thread.java:724)
      5 frames