sequencepushconsumerimpl.java
来自「UCS (Ultra Corba Simulator) is one more 」· Java 代码 · 共 476 行 · 第 1/2 页
JAVA
476 行
/**
*
*/
package com.corba.mnq.skelstub;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.omg.CORBA.Any;
import org.omg.CosNotification.EventType;
import org.omg.CosNotification.FixedEventHeader;
import org.omg.CosNotification.Property;
import org.omg.CosNotification.StructuredEvent;
import org.omg.CosNotifyComm.InvalidEventType;
import org.omg.CosNotifyComm.SequencePushConsumerPOA;
import com.corba.mnq.main.CorbaMNQ;
import com.corba.mnq.main.MNQmainFrame;
import com.corba.mnq.tool.CorbaFacility;
import com.corba.mnq.tool.EtcProperties;
import com.corba.mnq.tool.GetEtcTool;
/**
* @author cn1wc0k0
*/
public class SequencePushConsumerImpl extends SequencePushConsumerPOA {
/**
*
*/
public SequencePushConsumerImpl() {
super();
isTestMode = false;
isSleep = false;
// TODO Auto-generated constructor stub
buff = new Vector(1000, 1000);
isRec = true;
tBuf = new BuffReadThread(this);
new Thread(tBuf).start();
}
// private static ORB orb = TypeBase.orb;
private static long traploglen = 20000;
private static boolean isLog = true;
private BuffReadThread tBuf = null;
public boolean isRec = true;
// In test mode, only count the recieved notifications, not
// display or store it. (very fast handling)
private static boolean isTestMode = false;
// In sleep mode, the push consumer is hanged, until you make them
// wake up.
private static boolean isSleep = false;
private static long totalNum = 0;
private static long startTime = System.currentTimeMillis();
// Used for read & write
public List buff;
private static EtcProperties props;
static {
props = GetEtcTool.getProperties();
traploglen = props.getLongProperty(
"CorbaMNQ.notification.logfile.maxlength", 20000);
if (traploglen < 1000) {
traploglen = 1000;
}
isLog = props.getIntProperty(
"CorbaMNQ.notification.logfile.status", 1) == 0 ? false
: true;
}
/**
* This method receives a bunch of StructuredEvents from the
* CosNotification service and writes each event to the right GUI
* page (model).
*
* @param events
* the array of events that are received. Most times,
* this is only one event.
* @see org.omg.CosNotifyComm.SequencePushConsumerOperations#push_structured_events(org.omg.CosNotification.StructuredEvent[])
*/
public void push_structured_events(StructuredEvent[] events) {
if (isTestMode) {
totalNum = totalNum + events.length;
return;
}
while (isSleep) {
try {
// Sleep 0.1 seconds
Thread.sleep(100);
} catch (Exception e) {
LOG.severe(e.getClass().toString() + ": " + e.getMessage());
}
}
while (buff.size() > 8000) {
try {
// Sleep 0.1 seconds
Thread.sleep(100);
} catch (Exception e) {
LOG.severe(e.getClass().toString() + ": " + e.getMessage());
}
}
for (int i = 0; i < events.length; i++) {
buff.add(events[i]);
}
return;
}
public void pduHandling(StructuredEvent pdu, FileWriter fout) {
try {
String[] strs = new String[7];
// Arrived
strs[0] = (new Date(System.currentTimeMillis())).toString();
// Domain Name
strs[1] = pdu.header.fixed_header.event_type.domain_name;
// Type Name
strs[2] = pdu.header.fixed_header.event_type.type_name;
// Event Name
strs[3] = pdu.header.fixed_header.event_name;
// Variable Header
Property[] vh_p = pdu.header.variable_header;
strs[4] = properties2str(vh_p);
// Filterable Data
strs[5] = properties2str(pdu.filterable_data);
// Remainder
strs[6] = toStringNoCRNoLF(pdu.remainder_of_body, false);
MNQmainFrame.notiModel.insertRow(0, strs);
NotificationXMLTableWriter.writeTrapFromEvent(
MNQmainFrame.notiModel, MNQmainFrame.notiHeader, fout,
MNQmainFrame.notiModel.getColumnCount(), 0, "");
int rowCount = MNQmainFrame.notiModel.getRowCount();
MNQmainFrame.rowLabel.setText("" + rowCount);
} catch (Exception e) {
LOG.log(Level.SEVERE, e.getMessage(), e);
}
}
private String properties2str(Property[] pros) {
String res = "";
for (int i = 0; i < pros.length; i++) {
res += pros[i].name + " : "
+ toStringNoCRNoLF(pros[i].value, false);
}
return res;
}
/**
* Private method for filling the Property array with additional
* data from the remainder_of_body
*
* @param originalProperties
* @param remainder
* @param prop
* @return
*/
private static Property[] fillWithRemainderOfBody(
Property[] originalProperties, Any remainder) {
Property[] prop = null;
InputStream in = remainder.create_input_stream();
try {
if (in.available() == 0) {
prop = originalProperties;
} else {
// NonFilterableEventBody nfeb =
// NonFilterableEventBodyHelper
// .read(in);
// Property[] remainingProperties =
// nfeb.name_value_pairs;
// // merge the properties
// if (remainingProperties != null
// && remainingProperties.length > 0) {
// prop = new Property[originalProperties.length
// + remainingProperties.length];
// for (int i = 0; i < originalProperties.length; i++)
// {
// prop[i] = originalProperties[i];
// }
// for (int i = 0; i < remainingProperties.length;
// i++) {
// prop[originalProperties.length + i] =
// remainingProperties[i];
// }
// }
}
} catch (IOException e) {
prop = originalProperties;
}
return prop;
}
/**
* Returns a new String array which is 3 Strings larger than the
* array names, and fills all entries of it with data from the
* event.
*
* @param event
* where to fetch the data from.
* @param names
* required order of entries in the output.
* @param additionalSpace
* number of slots the returned array should have
* additionally.
* @return the filled strArray.
*/
private/* static */String[] fillStringArray(StructuredEvent event,
String[] names, int additionalSpace) {
String[] strArray = new String[names.length + 3 + additionalSpace];
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?