id
stringlengths
36
36
text
stringlengths
1
1.25M
14033426-6405-4c45-a524-3b28870be6ce
protected int lookupCategory(int c) { // this override of lookupCategory() exists only to keep track of whether we've // passed over any dictionary characters. It calls the inherited lookupCategory() // to do the real work, and then checks whether its return value is one of the // categories represented in the dictionary. If it is, bump the dictionary- // character count. int result = super.lookupCategory(c); if (result != RuleBasedBreakIterator.IGNORE && categoryFlags[result]) { ++dictionaryCharCount; } return result; }
cae1d8cf-18e9-4d94-b447-7a0b2986bad8
private void divideUpDictionaryRange(int startPos, int endPos) { CharacterIterator text = getText(); // the range we're dividing may begin or end with non-dictionary characters // (i.e., for line breaking, we may have leading or trailing punctuation // that needs to be kept with the word). Seek from the beginning of the // range to the first dictionary character text.setIndex(startPos); int c = getCurrent(); int category = lookupCategory(c); while (category == IGNORE || !categoryFlags[category]) { c = getNext(); category = lookupCategory(c); } // initialize. We maintain two stacks: currentBreakPositions contains // the list of break positions that will be returned if we successfully // finish traversing the whole range now. possibleBreakPositions lists // all other possible word ends we've passed along the way. (Whenever // we reach an error [a sequence of characters that can't begin any word // in the dictionary], we back up, possibly delete some breaks from // currentBreakPositions, move a break from possibleBreakPositions // to currentBreakPositions, and start over from there. This process // continues in this way until we either successfully make it all the way // across the range, or exhaust all of our combinations of break // positions.) Stack currentBreakPositions = new Stack(); Stack possibleBreakPositions = new Stack(); Vector wrongBreakPositions = new Vector(); // the dictionary is implemented as a trie, which is treated as a state // machine. -1 represents the end of a legal word. Every word in the // dictionary is represented by a path from the root node to -1. A path // that ends in state 0 is an illegal combination of characters. int state = 0; // these two variables are used for error handling. We keep track of the // farthest we've gotten through the range being divided, and the combination // of breaks that got us that far. If we use up all possible break // combinations, the text contains an error or a word that's not in the // dictionary. In this case, we "bless" the break positions that got us the // farthest as real break positions, and then start over from scratch with // the character where the error occurred. int farthestEndPoint = text.getIndex(); Stack bestBreakPositions = null; // initialize (we always exit the loop with a break statement) c = getCurrent(); while (true) { // if we can transition to state "-1" from our current state, we're // on the last character of a legal word. Push that position onto // the possible-break-positions stack if (dictionary.getNextState(state, 0) == -1) { possibleBreakPositions.push(Integer.valueOf(text.getIndex())); } // look up the new state to transition to in the dictionary state = dictionary.getNextStateFromCharacter(state, (char)c); // if the character we're sitting on causes us to transition to // the "end of word" state, then it was a non-dictionary character // and we've successfully traversed the whole range. Drop out // of the loop. if (state == -1) { currentBreakPositions.push(Integer.valueOf(text.getIndex())); break; } // if the character we're sitting on causes us to transition to // the error state, or if we've gone off the end of the range // without transitioning to the "end of word" state, we've hit // an error... else if (state == 0 || text.getIndex() >= endPos) { // if this is the farthest we've gotten, take note of it in // case there's an error in the text if (text.getIndex() > farthestEndPoint) { farthestEndPoint = text.getIndex(); bestBreakPositions = (Stack)(currentBreakPositions.clone()); } // wrongBreakPositions is a list of all break positions // we've tried starting that didn't allow us to traverse // all the way through the text. Every time we pop a //break position off of currentBreakPositions, we put it // into wrongBreakPositions to avoid trying it again later. // If we make it to this spot, we're either going to back // up to a break in possibleBreakPositions and try starting // over from there, or we've exhausted all possible break // positions and are going to do the fallback procedure. // This loop prevents us from messing with anything in // possibleBreakPositions that didn't work as a starting // point the last time we tried it (this is to prevent a bunch of // repetitive checks from slowing down some extreme cases) Integer newStartingSpot = null; while (!possibleBreakPositions.isEmpty() && wrongBreakPositions.contains( possibleBreakPositions.peek())) { possibleBreakPositions.pop(); } // if we've used up all possible break-position combinations, there's // an error or an unknown word in the text. In this case, we start // over, treating the farthest character we've reached as the beginning // of the range, and "blessing" the break positions that got us that // far as real break positions if (possibleBreakPositions.isEmpty()) { if (bestBreakPositions != null) { currentBreakPositions = bestBreakPositions; if (farthestEndPoint < endPos) { text.setIndex(farthestEndPoint + 1); } else { break; } } else { if ((currentBreakPositions.size() == 0 || ((Integer)(currentBreakPositions.peek())).intValue() != text.getIndex()) && text.getIndex() != startPos) { currentBreakPositions.push(new Integer(text.getIndex())); } getNext(); currentBreakPositions.push(new Integer(text.getIndex())); } } // if we still have more break positions we can try, then promote the // last break in possibleBreakPositions into currentBreakPositions, // and get rid of all entries in currentBreakPositions that come after // it. Then back up to that position and start over from there (i.e., // treat that position as the beginning of a new word) else { Integer temp = (Integer)possibleBreakPositions.pop(); Object temp2 = null; while (!currentBreakPositions.isEmpty() && temp.intValue() < ((Integer)currentBreakPositions.peek()).intValue()) { temp2 = currentBreakPositions.pop(); wrongBreakPositions.addElement(temp2); } currentBreakPositions.push(temp); text.setIndex(((Integer)currentBreakPositions.peek()).intValue()); } // re-sync "c" for the next go-round, and drop out of the loop if // we've made it off the end of the range c = getCurrent(); if (text.getIndex() >= endPos) { break; } } // if we didn't hit any exceptional conditions on this last iteration, // just advance to the next character and loop else { c = getNext(); } } // dump the last break position in the list, and replace it with the actual // end of the range (which may be the same character, or may be further on // because the range actually ended with non-dictionary characters we want to // keep with the word) if (!currentBreakPositions.isEmpty()) { currentBreakPositions.pop(); } currentBreakPositions.push(Integer.valueOf(endPos)); // create a regular array to hold the break positions and copy // the break positions from the stack to the array (in addition, // our starting position goes into this array as a break position). // This array becomes the cache of break positions used by next() // and previous(), so this is where we actually refresh the cache. cachedBreakPositions = new int[currentBreakPositions.size() + 1]; cachedBreakPositions[0] = startPos; for (int i = 0; i < currentBreakPositions.size(); i++) { cachedBreakPositions[i + 1] = ((Integer)currentBreakPositions.elementAt(i)).intValue(); } positionInCache = 0; }
921ab57c-6aed-4b30-8a90-85d2ff10544a
public static void main(String args[]) throws FileNotFoundException, UnsupportedEncodingException, IOException { String filename = args[0]; BreakDictionary dictionary = new BreakDictionary(new FileInputStream(filename)); PrintWriter out = null; if(args.length >= 2) { out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(args[1]), "UnicodeLittle")); } dictionary.printWordList("", 0, out); if (out != null) { out.close(); } }
ebd8eff0-7b37-4474-a266-35e04219aa3b
public void printWordList(String partialWord, int state, PrintWriter out) throws IOException { if (state == 0xFFFF) { System.out.println(partialWord); if (out != null) { out.println(partialWord); } } else { for (int i = 0; i < numCols; i++) { int newState = (getNextState(state, i)) & 0xFFFF; if (newState != 0) { char newChar = reverseColumnMap[i]; String newPartialWord = partialWord; if (newChar != 0) { newPartialWord += newChar; } printWordList(newPartialWord, newState, out); } } } }
bc21ed25-4f39-44d6-ae8a-952a95d12a37
public BreakDictionary(InputStream dictionaryStream) throws IOException { readDictionaryFile(new DataInputStream(dictionaryStream)); }
fad63b9a-7417-4813-bc6f-b9d88a8bfd90
public void readDictionaryFile(DataInputStream in) throws IOException { int l; // read in the version number (right now we just ignore it) in.readInt(); // read in the column map (this is serialized in its internal form: // an index array followed by a data array) l = in.readInt(); char[] temp = new char[l]; for (int i = 0; i < temp.length; i++) temp[i] = (char)in.readShort(); l = in.readInt(); byte[] temp2 = new byte[l]; for (int i = 0; i < temp2.length; i++) temp2[i] = in.readByte(); columnMap = new CompactByteArray(temp, temp2); // read in numCols and numColGroups numCols = in.readInt(); /*numColGroups = */in.readInt(); // read in the row-number index l = in.readInt(); rowIndex = new short[l]; for (int i = 0; i < rowIndex.length; i++) rowIndex[i] = in.readShort(); // load in the populated-cells bitmap: index first, then bitmap list l = in.readInt(); rowIndexFlagsIndex = new short[l]; for (int i = 0; i < rowIndexFlagsIndex.length; i++) rowIndexFlagsIndex[i] = in.readShort(); l = in.readInt(); rowIndexFlags = new int[l]; for (int i = 0; i < rowIndexFlags.length; i++) rowIndexFlags[i] = in.readInt(); // load in the row-shift index l = in.readInt(); rowIndexShifts = new byte[l]; for (int i = 0; i < rowIndexShifts.length; i++) rowIndexShifts[i] = in.readByte(); // finally, load in the actual state table l = in.readInt(); table = new short[l]; for (int i = 0; i < table.length; i++) table[i] = in.readShort(); // this data structure is only necessary for testing and debugging purposes reverseColumnMap = new char[numCols]; for (char c = 0; c < 0xffff; c++) { int col = columnMap.elementAt(c); if (col != 0) { reverseColumnMap[col] = c; } } // close the stream in.close(); }
fd748e53-26e7-4d4b-bd1c-7130a2b7cde8
public final short getNextStateFromCharacter(int row, char ch) { int col = columnMap.elementAt(ch); return getNextState(row, col); }
b0af4bbb-93a1-4e73-99ae-1479e332afb1
public final short getNextState(int row, int col) { if (cellIsPopulated(row, col)) { // we map from logical to physical row number by looking up the // mapping in rowIndex; we map from logical column number to // physical column number by looking up a shift value for this // logical row and offsetting the logical column number by // the shift amount. Then we can use internalAt() to actually // get the value out of the table. return internalAt(rowIndex[row], col + rowIndexShifts[row]); } else { return 0; } }
b57174a3-918c-475a-b43f-30c8762bf2b3
private final boolean cellIsPopulated(int row, int col) { // look up the entry in the bitmap index for the specified row. // If it's a negative number, it's the column number of the only // populated cell in the row if (rowIndexFlagsIndex[row] < 0) { return col == -rowIndexFlagsIndex[row]; } // if it's a positive number, it's the offset of an entry in the bitmap // list. If the table is more than 32 columns wide, the bitmap is stored // successive entries in the bitmap list, so we have to divide the column // number by 32 and offset the number we got out of the index by the result. // Once we have the appropriate piece of the bitmap, test the appropriate // bit and return the result. else { int flags = rowIndexFlags[rowIndexFlagsIndex[row] + (col >> 5)]; return (flags & (1 << (col & 0x1f))) != 0; } }
b919c129-6a08-423a-9fd0-b78c9b2f980b
private final short internalAt(int row, int col) { // the table is a one-dimensional array, so this just does the math necessary // to treat it as a two-dimensional array (we don't just use a two-dimensional // array because two-dimensional arrays are inefficient in Java) return table[row * numCols + col]; }
0791e5a8-53e1-45a8-bfac-0473a1101e3b
@Override protected void initChannel(SocketChannel ch) throws Exception { System.err.println("in ServerInit"); ChannelPipeline pipeline = ch.pipeline(); GlobalTrafficShapingHandler globalTrafficShapingHandler = new GlobalTrafficShapingHandler(ch.eventLoop()); trafficCounter = globalTrafficShapingHandler.trafficCounter(); pipeline.addLast("traffic", globalTrafficShapingHandler); pipeline.addLast("codec-http", new HttpServerCodec()); pipeline.addLast("aggregator", new HttpObjectAggregator(65536)); pipeline.addLast("handler", new ServerHandler(trafficCounter)); }
38e98651-112a-4cf6-bbee-e33c28a04a05
public void run() { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); System.out.println("in HttpServRun"); try { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 1024); b.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .childHandler(new ServerInit()); Channel ch = b.bind(PORT).sync().channel(); ch.closeFuture().sync(); } catch (InterruptedException e ) { e.printStackTrace(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
dd2a6b8b-ba0e-47a6-8b5f-c4d2c78dc64c
public static void main(String[] args) { try { System.out.println("in Main"); new HttpServer().run(); } catch (Exception e) { e.printStackTrace(); } }
58d6fcf8-e101-47c2-86b8-9cf2a0e82b75
public static void addConnection(){ activeConnection++; }
c9ac83a5-99ec-47f9-8047-d5df1a28df17
synchronized public static void subConnection(){ activeConnection--; }
46a32628-d81f-47fb-ac30-5066d9f7cb6a
synchronized public static int getActiveConnection() { return activeConnection; }
132c0d68-b07e-48bd-bdfd-d2f10b836353
public static long getTotalrequest() { return totalrequest; }
f5f16445-fd5b-436e-aad2-0eb39561d32f
public static void setTotalrequest(long totalrequest) { ServerStatus.totalrequest = totalrequest; }
0286691c-8220-4bae-850a-99e7ee068371
public static void addRequest(){ totalrequest++; }
1cbd9d7d-a5ea-4cda-88c3-88911f284245
public ServerHandler(TrafficCounter trafficCounter) { this.trafficCounter = trafficCounter; }
a3f1d64e-7a41-4782-a01f-33e1b84d2e2b
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { trafficCounter.start(); InetSocketAddress address = (InetSocketAddress) ctx.channel().remoteAddress(); String ip = address.getHostString(); if (msg instanceof HttpRequest) { System.out.println("in ChenelRead"); FullHttpRequest request = (FullHttpRequest) msg; if (!request.getUri().equals("/falicon.ico")) { ServerStatus.addConnection(); } if (is100ContinueExpected(request)) { ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE)); } String uri = request.getUri(); handleHttpRequest(ctx, (FullHttpRequest) msg, ip); } }
988a6db4-1326-4d44-bdea-e2bf431e69b1
@Override public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { System.out.println("in ChanelReadRomplete"); ServerStatus.subConnection(); ctx.flush(); ctx.close(); }
1aa7c1e5-1c19-4cc2-9e9b-aa46922c380b
private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req, String ip) { String uri = req.getUri(); FullHttpResponse resp = null; if (uri.equalsIgnoreCase(STATUS)) { ManagerDB.addOrUpdateRequestAmount(ip, dateFormat.format(new Date())); ServerStatus.addRequest(); PageStatus page = new PageStatus(); String send = page.getPage(); ByteBuf buf = Unpooled.unreleasableBuffer(Unpooled.copiedBuffer(send, CharsetUtil.US_ASCII)); resp = new DefaultFullHttpResponse(HTTP_1_1, OK, buf); resp.headers().set(CONTENT_TYPE, "text/HTML"); resp.headers().set(CONTENT_LENGTH, resp.content().readableBytes()); sendHttpResponse(ctx, req, resp); trafficLog(); ManagerDB.insertConnection(ip, uri, dateFormat.format(new Date()), sentBytes, receivedBytes, speed); } else if (uri.equalsIgnoreCase(HELLO)) { try { Thread.sleep(TIMESLEEP * 1000); } catch (InterruptedException ex) { ex.printStackTrace(); } Page page = new PageHello(); ManagerDB.addOrUpdateRequestAmount(ip, dateFormat.format(new Date())); ServerStatus.addRequest(); String send = page.getPage(); ByteBuf buf = Unpooled.unreleasableBuffer(Unpooled.copiedBuffer(send, CharsetUtil.US_ASCII)); resp = new DefaultFullHttpResponse(HTTP_1_1, OK, buf); resp.headers().set(CONTENT_TYPE, "text/HTML"); resp.headers().set(CONTENT_LENGTH, resp.content().readableBytes()); sendHttpResponse(ctx, req, resp); trafficLog(); ManagerDB.insertConnection(ip, uri, dateFormat.format(new Date()), sentBytes, receivedBytes, speed); } else if (uri.toLowerCase().contains(REDIRECT) && uri.toLowerCase().contains("url")) { ManagerDB.addOrUpdateRequestAmount(ip, dateFormat.format(new Date())); ServerStatus.addRequest(); String redirect; if (uri.toLowerCase().contains("http://")) { redirect = uri.substring(14); } else { redirect = "http://" + uri.substring(14); } ByteBuf buf23 = Unpooled.unreleasableBuffer(Unpooled.copiedBuffer("", CharsetUtil.US_ASCII)); resp = new DefaultFullHttpResponse(HTTP_1_1, TEMPORARY_REDIRECT, buf23); resp.headers().set(LOCATION, redirect); sendHttpResponse(ctx, req, resp); trafficLog(); ManagerDB.insertConnection(ip, uri, dateFormat.format(new Date()), sentBytes, receivedBytes, speed); } else { ByteBuf buf2 = Unpooled.unreleasableBuffer(Unpooled.copiedBuffer("404 page not found", CharsetUtil.US_ASCII)); resp = new DefaultFullHttpResponse(HTTP_1_1, OK, buf2); resp.headers().set(CONTENT_TYPE, "text/plain"); resp.headers().set(CONTENT_LENGTH, resp.content().readableBytes()); sendHttpResponse(ctx, req, resp); } }
87a70da7-8e20-4598-bdc2-29eb3f2cd6ea
private void sendHttpResponse(ChannelHandlerContext ctx, FullHttpRequest req, FullHttpResponse resp) { if (!isKeepAlive(req)) { ctx.write(resp).addListener(ChannelFutureListener.CLOSE); } else { resp.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE); ctx.write(resp); } }
470ff8c0-2e4c-49e7-80e7-250be8a4060e
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { System.out.println("in ExceptionCaugh"); ServerStatus.subConnection(); cause.printStackTrace(); ctx.close(); }
3ddbfa35-191c-4fbc-b9ef-704af036221f
synchronized public void trafficLog() { trafficCounter.stop(); receivedBytes = trafficCounter.cumulativeReadBytes(); sentBytes = trafficCounter.cumulativeWrittenBytes(); speed = trafficCounter.lastWriteThroughput(); trafficCounter.resetCumulativeTime(); }
a0d767f9-b71a-4e93-ad3f-91c42c57f031
public static JPUtil getInstance() { if (instance == null) { instance = new JPUtil(); } return instance; }
d226e0ad-c442-4a16-9fdf-b35ae0fe9b2d
private JPUtil() { emf = Persistence.createEntityManagerFactory("HttpServerPU"); }
f5647b5c-4458-4323-9403-34d6633453fe
public EntityManager getManager() { return emf.createEntityManager(); }
adeba647-0d59-4d90-9063-1512d389fa2a
public void closeFactory() { emf.close(); }
639e7378-92ed-4473-b3a3-9c678cf1d287
@Override public String getPage() { return page; }
36be7459-a392-416a-b39a-cf1f5ac97205
public String createContent() { StringBuilder HTTPResponse = new StringBuilder(); HTTPResponse.append(" <h2> <p>Number of all requset: " + ServerStatus.getTotalrequest() + " </p> </h2>"); HTTPResponse.append(" <h2> <p>Number of active connections: " + ServerStatus.getActiveConnection() + " </p> </h2>"); HTTPResponse.append(" <h2> <p>Number of unique request : " + ManagerDB.getUbiqueRequestList().size() + " </p> </h2>"); HTTPResponse.append(" <table border=\"3\" cellpadding=\"5\">"); HTTPResponse.append(" <tr> <th>IP</th> <th>Count of request</th> <th>Time lsat request</th> </tr>"); List<Requests> allRequest = ManagerDB.getIpRequestList(); for (Requests request : allRequest) { HTTPResponse.append(" <tr> <td>" + request.getIp() + "</td> <td>" + request.getRequestCount() + "</td> <td>" + request.getTimeLastRequest() + "</td> </tr>"); } HTTPResponse.append(" </table>"); HTTPResponse.append("<br></br>"); HTTPResponse.append("<br></br>"); HTTPResponse.append(" <table border=\"3\" cellpadding=\"5\">"); HTTPResponse.append(" <tr> <th>URL</th> <th>Count of redirect</th> </tr>"); List<Redirects> allRedirect = ManagerDB.getRedirectList(); for (Redirects request : allRedirect) { HTTPResponse.append(" <tr> <td>" + request.getUrl() + "</td> <td>" + request.getAmountRedir() + "</td> </tr>"); } HTTPResponse.append(" </table>"); HTTPResponse.append("<br></br>"); HTTPResponse.append("<br></br>"); HTTPResponse.append(" <table border=\"3\" cellpadding=\"5\">"); HTTPResponse.append(" <tr> <th>src_ip</th> <th>uri</th> <th>timestamp</th> <th>sent_bytes</th> <th>received_bytes</th> <th>speed</th> </tr>"); List<Connection> allConnectRequest = ManagerDB.getConnectionList(); int first = allConnectRequest.size(); if (first < 16) { first = 0; } else { first -=16; } for (int i = first; i < allConnectRequest.size(); i++) { Connection request = allConnectRequest.get(i); HTTPResponse.append(" <tr> <td>" + request.getSrcIp() + "</td> <td>" + request.getUri() + "</td> <td>" + request.getTimestamp() + "</td> " + " <td>" + request.getSentBytes() + "</td> <td>" + request.getReceivedBytes() + "</td> <td>" + request.getSpeed() + "</td> </tr>"); } HTTPResponse.append(" </table>"); return HTTPResponse.toString(); }
8f782bb8-1d45-47e8-b55c-4de1584dea19
@Override public String getPage() { return this.page; }
8f22f549-bf6d-4a1a-9690-d4d614714bba
public abstract String getPage();
b86a3c97-d9f8-4371-8ca8-c4ef84618545
public Redirects() { }
641c3774-1e7e-4a96-b39f-9098541c66cc
public Redirects(String url) { this.url = url; }
c125a99a-a251-405e-ba7f-039d66fbdc6a
public Redirects(String url, int amountRedir) { this.url = url; this.amountRedir = amountRedir; }
6b09783d-b2a6-4e6c-8f6c-075561893725
public String getUrl() { return url; }
2586999c-d365-4ae7-ae8c-b9ec23519ed6
public void setUrl(String url) { this.url = url; }
683396f9-4715-4309-9bee-72a1f0d63113
public int getAmountRedir() { return amountRedir; }
2c520aeb-0dce-4287-b2fa-2f7b907a97c5
public void setAmountRedir(int amountRedir) { this.amountRedir = amountRedir; }
d4215b57-d0a7-4ca2-bf47-304ad7ae776f
@Override public int hashCode() { int hash = 0; hash += (url != null ? url.hashCode() : 0); return hash; }
fce0eb46-34c0-4984-9f49-715211e64be8
@Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Redirects)) { return false; } Redirects other = (Redirects) object; if ((this.url == null && other.url != null) || (this.url != null && !this.url.equals(other.url))) { return false; } return true; }
526108d7-f10f-4648-8f99-d5c42c23e6e7
@Override public String toString() { return "entitys.Redirects[ url=" + url + " ]"; }
de2edf06-8f07-4de1-a2fd-c3e841107dd2
public Connection() { }
3609bd47-3547-4a0b-b1c4-2e66225b31aa
public Connection(Integer id) { this.id = id; }
6ecc41cd-d0f1-4db6-99f3-ba49737e479a
public Connection(String srcIp, String uri, String timestamp, long sentBytes, long receivedBytes, long speed) { this.srcIp = srcIp; this.uri = uri; this.timestamp = timestamp; this.sentBytes = sentBytes; this.receivedBytes = receivedBytes; this.speed = speed; }
b44e0dd4-8b54-4231-8db1-579b62cbe81b
public Integer getId() { return id; }
3ca39555-f62e-4ce6-85c6-e8c7a2310c44
public void setId(Integer id) { this.id = id; }
62e86bdd-11e9-424d-8818-ea04d6613f18
public String getSrcIp() { return srcIp; }
45c36960-ee54-4fec-9792-9cf336916136
public void setSrcIp(String srcIp) { this.srcIp = srcIp; }
47927e64-009f-4231-9a02-c77d0ebdf864
public String getUri() { return uri; }
a94521c7-74fe-4c91-af43-7165ff4ef83d
public void setUri(String uri) { this.uri = uri; }
29130f46-e539-4add-89e5-63e0ecffb8e3
public String getTimestamp() { return timestamp; }
8f93a06f-ea4a-4200-b56a-62ca8560f5bb
public void setTimestamp(String timestamp) { this.timestamp = timestamp; }
6d63b0cc-c365-4bf8-825d-c48868ccb612
public long getSentBytes() { return sentBytes; }
2863d840-4c2d-486d-9f68-059754b03d18
public void setSentBytes(int sentBytes) { this.sentBytes = sentBytes; }
33f744e6-952b-40bb-858b-60717269ce42
public long getReceivedBytes() { return receivedBytes; }
3f7874db-1cf8-442f-9861-6920509f9036
public void setReceivedBytes(int receivedBytes) { this.receivedBytes = receivedBytes; }
f5087a57-e86a-484f-af87-90bbbc076610
@Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; }
3f474250-6e74-46a4-bfe9-27872a1ec245
@Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Connection)) { return false; } Connection other = (Connection) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; }
5c0b7915-5941-428c-9578-f66880dc39f3
@Override public String toString() { return "entitys.Connection[ id=" + id + " ]"; }
7773feb2-2d49-425c-a826-5d27eebc9cf0
public void setSpeed(int speed) { this.speed = speed; }
7fb02623-8f97-4504-ad55-edb9eb717591
public long getSpeed() { return speed; }
723ae395-57b1-43b5-8694-3590c5088d2f
public Requests() { }
c532a44b-9d12-470d-88f6-3a148ce9f518
public Requests(Integer id) { this.id = id; }
44891023-f1bb-4be4-8924-1963b2b91a20
public Requests(String ip, int requestCount, String timeLastRequest) { this.ip = ip; this.requestCount = requestCount; this.timeLastRequest = timeLastRequest; }
594a6c0d-e14f-4e05-8091-1e7f908c8f43
public Integer getId() { return id; }
cfb04865-f09f-476e-86ec-e4724fe04428
public void setId(Integer id) { this.id = id; }
a177ca99-f51a-4abe-a276-53dce49f7109
public String getIp() { return ip; }
ce1dcf5d-5312-4c45-b9e9-134243c1a311
public void setIp(String ip) { this.ip = ip; }
df8d9176-b099-402a-bd8a-51e193cde9ca
public int getRequestCount() { return requestCount; }
8d84f6d3-0703-4374-a633-affd87189ef6
public void setRequestCount(int requestCount) { this.requestCount = requestCount; }
752672c6-b2b3-470e-9234-e99e058eeb17
public String getTimeLastRequest() { return timeLastRequest; }
d1c34c79-1815-42bf-a5a8-e9322630c503
public void setTimeLastRequest(String timeLastRequest) { this.timeLastRequest = timeLastRequest; }
19d6b91a-0c3f-4b59-956d-5a11463eb2b4
@Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; }
b6a150a1-6ec2-4114-b0a3-8330a50ab8d8
@Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Requests)) { return false; } Requests other = (Requests) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; }
3647598e-da56-44ef-afd1-d91d8c7021a5
@Override public String toString() { return "entitys.Requests[ id=" + id + " ]"; }
3d2448fe-8b8e-499d-939c-284e344b163e
synchronized public static void addOrUpdateRequestAmount(String ip, String timestamp){ Requests req; EntityManager manager = JPUtil.getInstance().getManager(); manager.getTransaction().begin(); try { req = manager.createNamedQuery("Requests.findByIp", Requests.class).setParameter("ip", ip).getSingleResult(); req.setRequestCount(req.getRequestCount()+1); req.setTimeLastRequest(timestamp); manager.merge(req); } catch (NoResultException ex) { req = new Requests(ip, 1, timestamp); manager.persist(req); } manager.getTransaction().commit(); }
d7c5aa34-d0c8-44fc-afdf-d8b56d9996d7
synchronized public static void insertConnection(String src_ip, String uri,String timestamp, long sentBytes, long receivedBytes, long speed){ EntityManager manager = JPUtil.getInstance().getManager(); manager.getTransaction().begin(); manager.persist(new Connection(src_ip, uri, timestamp, sentBytes, receivedBytes, speed)); manager.getTransaction().commit(); }
5c0d4b35-0c0b-4440-b936-55ef29bd1af8
public static void insertOrUpdateURLRedirect(String url){ Redirects redURL; EntityManager manager = JPUtil.getInstance().getManager(); manager.getTransaction().begin(); try { redURL = manager.createNamedQuery("Redirects.findByUrl", Redirects.class).setParameter("url", url).getSingleResult(); redURL.setAmountRedir(redURL.getAmountRedir()+1); manager.merge(redURL); } catch (NoResultException ex) { redURL = new Redirects(url, 1); manager.persist(redURL); } manager.getTransaction().commit(); }
1f3a48f8-548e-4367-ba83-79731e298a6e
public static List<Connection> getConnectionList(){ EntityManager manager = JPUtil.getInstance().getManager(); List<Connection> connectList = manager.createNamedQuery("Connection.findAll", Connection.class).getResultList(); return connectList; }
b29e7f88-7086-483e-b83a-c1406e393821
public static List<Requests> getUbiqueRequestList(){ EntityManager manager = JPUtil.getInstance().getManager(); List<Requests> uniqRequest = manager.createNamedQuery("Requests.findByRequestCount", Requests.class).setParameter("requestCount", 1).getResultList(); return uniqRequest; }
6e805658-e60d-4e10-9ec9-20f14ed9ef49
public static List<Redirects> getRedirectList(){ EntityManager manager = JPUtil.getInstance().getManager(); List<Redirects> allRedir = manager.createNamedQuery("Redirects.findAll", Redirects.class).getResultList(); return allRedir; }
dc70c040-1de5-446a-b425-217636b9f156
public static List<Requests> getIpRequestList(){ EntityManager manager = JPUtil.getInstance().getManager(); List<Requests> requestList = manager.createNamedQuery("Requests.findAll", Requests.class).getResultList(); return requestList; }
972fa37f-709e-455c-8acd-6141f1287253
public static void showLog() { showLog = true; }
3fa5247c-e38f-4b0f-9d8f-473fe33b01c7
public static void hideLog() { showLog = false; }
83745311-bb9b-4773-a5f0-01279caa9abb
private SQLUtils() { }
0296b075-107a-4eb1-ac2d-23bd90e927b4
public static String getQuerySQL(String fileName) { try (Scanner sqlFile = new Scanner(new File(fileName))) { StringBuilder sql = new StringBuilder(); while (sqlFile.hasNext()) sql.append(sqlFile.nextLine()); String actualSQL = sql.toString(); log(actualSQL); return actualSQL; } catch (FileNotFoundException e) { throw new ConfigurationException("Cannot find sql file @[" + fileName + "]", e); } }
3e89ebab-1d89-4819-b22a-d7fa7bad86eb
private static void log(String querySql) { if (showLog) System.out.printf("Executing %s @ %s \n", querySql, getDBURL()); }
2f3a2d1f-be8c-412e-b70a-9bf265cd4696
public static String showAllEmployeesQuery() { return getQuerySQL(SHOW_ALL_EMPLOYEES); }
4c8133d1-f823-457c-a2df-6c6097c7ad7e
public static String showEmployeesAlphabeticallyQuery() { return getQuerySQL(SHOW_EMPLOYEES_ALPHABETICALLY); }
fefe0964-7e48-4fff-a94c-e51b86ecd94f
public static String showEmployeesNamesandDepartmentsQuery() { return getQuerySQL(SHOW_EMPLOYEES_NAMESand_DEPARTMENTS); }
7e9eb5be-5cbb-4564-b4ee-560f4d068d84
public static String showEmployeesNamesandManagersQuery() { return getQuerySQL(SHOW_EMPLOYEES_NAMESand_MANAGERS); }
ff09c905-073f-432b-b355-36dd7cb5eedd
public static String showEmployeesNamesandManagersOOPQuery() { return getQuerySQL(SHOW_EMPLOYEES_NAMESand_MANAGERSOOP); }
22249b31-acf2-41c8-9aaa-11689bc04bd8
public static String getDBUser() { return config.getProperty("user"); }
cb82dfce-b16a-4135-a68a-256ce0f78f50
public static String getPassword() { return config.getProperty("password"); }
f375f7a6-5b05-4836-9906-531cdc7ba0c3
public static String getDBURL() { return config.getProperty("url"); }
0ae27bef-6ca2-4fe4-800e-9b73fd6edd4d
public static void loadDriver() { try { Class.forName(DRIVER_CLASS); } catch (ClassNotFoundException e) { throw new ConfigurationException("Cannot load driver[" + DRIVER_CLASS + "]", e); } }
2ca34a4f-5e1c-47a3-af2a-872b83ce9b71
public static Connection getConnection() { try { return DriverManager.getConnection(getDBURL(), getDBUser(), getPassword()); } catch (SQLException e) { throw new ConfigurationException( "Cannot establish a connection to [ " + getDBURL() + "]", e); } }