-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from scouter-project/master
Merge for release
- Loading branch information
Showing
550 changed files
with
167,794 additions
and
763 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
scouter.agent.batch/src/scouter/agent/batch/netio/mtu/MultiPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2015 the original author or authors. | ||
* @https://github.com/scouter-project/scouter | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package scouter.agent.batch.netio.mtu; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.net.InetAddress; | ||
import java.util.ArrayList; | ||
|
||
public class MultiPacket{ | ||
private int added = 0; | ||
private ArrayList<byte []> data; | ||
private long openTime = System.currentTimeMillis(); | ||
|
||
private int total; | ||
private int objHash; | ||
private InetAddress addr; | ||
|
||
public MultiPacket(int total, int objHash, InetAddress addr){ | ||
this.total = total; | ||
this.objHash = objHash; | ||
this.addr = addr; | ||
this.data = new ArrayList<byte[]>(total); | ||
|
||
for(int i=0; i < total; i++){ | ||
data.add(null); | ||
} | ||
} | ||
|
||
public void set(int n, byte [] data){ | ||
if (n < total) { | ||
if (this.data.get(n) == null) | ||
added += 1; | ||
this.data.add(n, data); | ||
} | ||
} | ||
|
||
public boolean isExpired(){ | ||
return ((System.currentTimeMillis() - this.openTime) >= 1000); | ||
} | ||
|
||
public boolean isDone() { | ||
return total == added; | ||
} | ||
|
||
public byte[] toBytes() throws IOException{ | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
for (int i = 0; i < total; i++) { | ||
out.write(this.data.get(i)); | ||
} | ||
return out.toByteArray(); | ||
} | ||
|
||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("MultiPacket total=").append(total); | ||
sb.append(" recv=").append(added); | ||
sb.append(" object=(").append(objHash).append(")").append(objHash); | ||
sb.append(" ").append(addr); | ||
return sb.toString(); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
scouter.agent.batch/src/scouter/agent/batch/netio/mtu/MultiPacketProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package scouter.agent.batch.netio.mtu; | ||
|
||
import java.io.IOException; | ||
import java.net.InetAddress; | ||
|
||
import scouter.agent.batch.Configure; | ||
import scouter.agent.batch.Logger; | ||
import scouter.util.LongEnumer; | ||
import scouter.util.LongKeyLinkedMap; | ||
import scouter.util.ThreadUtil; | ||
|
||
public class MultiPacketProcessor extends Thread{ | ||
private static MultiPacketProcessor instance = null; | ||
|
||
static final int MAX_COUNT = 1000; | ||
private LongKeyLinkedMap<MultiPacket> buffer = new LongKeyLinkedMap<MultiPacket>(); | ||
|
||
static public MultiPacketProcessor getInstance(){ | ||
if(instance == null){ | ||
instance = new MultiPacketProcessor(); | ||
instance.setDaemon(true); | ||
instance.setName(ThreadUtil.getName(instance)); | ||
|
||
instance.start(); | ||
} | ||
return instance; | ||
} | ||
|
||
private MultiPacketProcessor(){ | ||
buffer.setMax(MAX_COUNT); | ||
} | ||
|
||
public void run() { | ||
while (true) { | ||
ThreadUtil.sleep(1000); | ||
if (buffer.size() > 0) { | ||
try { | ||
checkExpired(); | ||
} catch(Exception ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public byte[] add(long pkid, int total, int num, byte [] data, int objHash, InetAddress addr) throws IOException{ | ||
MultiPacket p; | ||
synchronized(buffer){ | ||
p = buffer.get(pkid); | ||
if (p == null) { | ||
p = new MultiPacket(total, objHash, addr); | ||
buffer.put(pkid, p); | ||
} | ||
} | ||
|
||
p.set(num, data); | ||
if (p.isDone()) { | ||
buffer.remove(pkid); | ||
return p.toBytes(); | ||
} | ||
return null; | ||
} | ||
|
||
private void checkExpired() { | ||
LongEnumer en = buffer.keys(); | ||
long key; | ||
MultiPacket p; | ||
while (en.hasMoreElements() == true) { | ||
key = en.nextLong(); | ||
p = buffer.get(key); | ||
if (p.isExpired()) { | ||
buffer.remove(key); | ||
// if (Configure.getInstance().log_expired_multipacket) { | ||
// Logger.println("S150", p.toString()); | ||
// } | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.