Jump to content
  • 0

Fastlist Inside Array (Suggestion - Help)


Question

Recommended Posts

  • 0
Posted (edited)

On a Map, since Java8 you can use putIfAbsent. On a List you still have to check via .contains if an object isn't already registered. If your List contains 2 elements, it means you add twice the element, or you missed the check.

 

FastList got no uses (should be renamed FatList), use either ArrayList or its concurrent version (only if you add/remove in same time, or if you remove iterating it), CopyOnWriteArray.

 

Otherwise, c/p the part of code.

Edited by Tryskell
  • 0
Posted

On a Map, since Java8 you can use putIfAbsent. On a List you still have to check via .contains if an object isn't already registered. If your List contains 2 elements, it means you add twice the element, or you missed the check.

 

FastList got no uses (should be renamed FatList), use either ArrayList or its concurrent version (only if you add/remove in same time, or if you remove iterating it), CopyOnWriteArray.

 

Otherwise, c/p the part of code.

Ill send u the part of code i made cause i dont want share it and i work in java 7 (freya) so take a look in it (i send it now)thanks

  • 0
Posted

I read your code, and I don't find the use of those arrays and lists. Plus, don't use FastList, use CopyOnWriteArrayList.

 

Eventually ask exactly what you want to do, because even on your PM, with your piece of code, it wasn't clear.

 

For the biggest I think I answered correctly, at least it's the easiest/fastest implementation of your idea.

 

You only have to for loop couples to get needed infos.

  • 0
Posted

I read your code, and I don't find the use of those arrays and lists. Plus, don't use FastList, use CopyOnWriteArrayList.

 

Eventually ask exactly what you want to do, because even on your PM, with your piece of code, it wasn't clear.

 

For the biggest I think I answered correctly, at least it's the easiest/fastest implementation of your idea.

 

You only have to for loop couples to get needed infos.

I made an npc instance that when a player click "register" a window pop up to his/her parther (if partner exist and is in range of 500 aoe )

and ask if she/he want to join  if she accept (join) the couple (those 2 players) are added in the event. 

 

A threadpool start and check 5 min if couples > 4  event start... i want do a couple war 

  • 0
Posted

I made an npc instance that when a player click "register" a window pop up to his/her parther (if partner exist and is in range of 500 aoe )

and ask if she/he want to join  if she accept (join) the couple (those 2 players) are added in the event. 

 

A threadpool start and check 5 min if couples > 4  event start... i want do a couple war 

Pretty basic stuff. Don't use the hard way. Take an example from TvT event.

  • 0
Posted

Pretty basic stuff. Don't use the hard way. Take an example from TvT event.

Yeap yeap i know i already coded many events that use 1 object per time but this time is different.. we speak for 2 object rights?

 

L2PcInstance player = null; (1 object)

L2PcInstance partner = L2World.getInstance().getPlayer(player.getPartnerId());

 

_players.add(player);

_players.add(partner);

 

it works but i also want to make a 2nd map that add

those _players into a new  _playerList map

 

and after add them  _players.clear();  so its fresh clean again...

 

the problem i face is i dont know how to handle _playerList map...  there is nothing i can use   exept a For to teleport them but inside the event

there is nothing to control them like    coupleId(1).doDie  and kill both players if 1 of them die... 

  • 0
Posted
final L2PcInstance partner = L2World.getInstance().getPlayer(Couple.getPartnerId(player.getObjectId()));

That's to retrieve the partner, to send your popup (you could simply check wedding manager).

 

Regarding couple management, once again, the easiest is to put booleans flags into Couple class (or an Enum).

 

You for loop couples and retrieve couples with good enum value or good flag value.

 

You got all needed in CoupleManager (getCouples(), getCouple(coupleid), etc).

  • 0
Posted (edited)

Got some tests or infos about it ?

 

No.

 

But basically the javadoc says it all.

 

You got either CopyOnWriteArrayList, which that said :

 

 

 

A thread-safe variant of ArrayList in which all mutative operations (add, set, and so on) are implemented by making a fresh copy of the underlying array.

This is ordinarily too costly.

 

Or a concurrent Set, backed by a ConcurrentHashMap, with all Set properties such as uniqueness. It all depends if he needs to get or not.

Edited by Sdw
  • 0
Posted (edited)

Ooooookkkkk, I was wondering why L2J did that way, and since I ran one little test I understand :P. My code isn't serious and barely be called a test : 100k integers addition, then I Iterator to force concurrency and remove multiples of 2 and 5 (a simple hashset throws a concurrentexception).

 

The only thing which changes from one test to another is the container :

final Set<Integer> map = new CopyOnWriteArraySet<>();
final List<Integer> map = new CopyOnWriteArrayList<>();
final Set<Integer> map = ConcurrentHashMap.newKeySet();

Result is kinda sad :

 

CopyOnWriteArraySet : between 40 and 67sec.

CopyOnWriteArrayList : between 15 and 30sec.

ConcurrentHashMap.newKeySet : between 0,8 and 1,5sec.

 

Don't use CopyOnWriteArrayList nor CopyOnWriteArraySet.

 

I have some commits to do on aCis :P.

 

If you want to test it :

    public static void main(String[] args)
    {
    	 long storedTime = System.currentTimeMillis();
    	 
    	final Set<Integer> map = new CopyOnWriteArraySet<>();
    	
    	//Populate the map.
    	 for (int i = 0 ; i < 100000 ; i++)
    		 map.add(i);
    	 
    	 Iterator<Integer> it = map.iterator();
    	         while(it.hasNext()){
    	        	 Integer value = it.next();
    	             if(value%5 == 0 || value%2 == 0) {
    	            	 System.out.println("skipped:"+value);
    	            	 map.remove(value);
    	             }
    	         }
    	 
    	 long currentTime = System.currentTimeMillis();
    	 System.out.println("map size: " + map.size());
         System.out.println("execution time: " + (currentTime - storedTime));
    }
Edited by Tryskell
  • 0
Posted

 Tryskell the send message window works..  i just dont know how to add 2 objects in 1 array and take them as 1 team

2 players (team1)

2 players (team2)

2 players (team3)

this is what i want to do

and before event start if 1 player click "unregister" it unregister his partner too

  • 0
Posted

public static ArrayList<FastList> couplesList = new ArrayList<>();

public static final FastList<L2PcInstance> _players = new FastList<L2PcInstance>();final L2PcInstance partner = L2World.getInstance().getPlayer(player.getPartnerId());

 

 

 

 

 

 

 


else if (command.startsWith("remove"))

{

 

//=================================================================


if (couplesList.contains(_players))

{

couplesList.remove(_players);

 

player.sendMessage("You removed your participation from event");

partner.sendMessage("Your partner removed the participation from event");

 

setCouples(getCouples() -1);

}

 


 

else if (command.startsWith("join"))

{

 

//=================================================================

 

final L2PcInstance partner = L2World.getInstance().getPlayer(player.getPartnerId());

 

 

_players.add(player);

_players.add(partner);

 

couplesList.add(_players);

 

_players.clear();

 

player.sendMessage("You are registered in the event with your partner");

partner.sendMessage("You are registered in the event with your partner");

 

setCouples(getCouples() + 1);

 

Timer();

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • Added the protection module to the demo.   DDoS Guard Pro v2.0 is a system protection module for PlayMMO CMS designed to reduce the load on the website during HTTP floods, bot activity, suspicious frequent requests, and attacks on individual pages or API methods. Unlike simple global limiters, DDoS Guard Pro v2.0 supports flexible rules based on routes and HTTP methods. This allows you to block the entire site in a targeted manner, rather than blocking the entire site equally. You can set up protection for specific areas of the site, such as login, registration, APIs, administration, forms, and other sensitive areas. What is the purpose of the module? DDoS Guard Pro v2.0 helps protect your site from basic L7 attacks at the HTTP request level. The module is useful when your site receives: frequent requests from a single IP address; HTTP page floods; login or registration form flooding; automatic requests from bots; URL scanning; frequent API requests; suspicious activity spikes; load on individual CMS methods or pages. The module helps to reduce the load on PHP and CMS by limiting suspicious activity before it starts to create a serious load on the site. Main features Per-route and per-method Rate Limit In the new version, protection is configured not only globally, but also according to specific rules. You can set limits separately for: GET; POST; PUT; PATCH; DELETE; ALL. This allows you to flexibly protect different parts of your website. For example: for the login page, you can set a strict limit; for registration, you can set a separate limit; for the API, you can set a limit for reading and a limit for changing data; for regular website pages, you can set a soft limit or not set a limit at all. This approach reduces the risk of accidentally blocking regular users and makes the protection more accurate. Flexible rule system The module supports setting rules in the following format: METHODS|PATTERN|LIMIT|WINDOW|BURST_LIMIT|BURST_WINDOW|BLOCK_SECONDS|IDENTITY|NAME Example of rules: POST|*login*|10|60|5|10|600|ip|login_post POST|*register*|8|60|4|10|600|ip|register_post GET|*api*|300|60|80|10|120|ip|api_get PUT,PATCH,DELETE|*api*|80|60|20|10|300|ip|api_write This allows you to specify exactly: which HTTP methods to protect; which URLs or URL patterns to consider; how many requests are allowed; over what time period; what burst limit to use;  how many seconds to block the offender;  by which ID to count the limit;  what the rule is called. Burst protection against sharp spikes  In addition to the regular request limit, the module monitors sharp spikes of activity.  This is useful when a bot makes many requests in a few seconds. In this case, the protection can be activated faster, without waiting for the overall limit per minute.  Burst protection is especially useful for: authorization pages; registration; API; search; data submission forms; administrative sections. Support for different types of requests DDoS Guard Pro v2.0 works not only with POST requests. The module can control: GET — regular pages, API requests, search; POST — forms, login, registration, data submission; PUT — updating data via API; PATCH — partial data update; DELETE — data deletion; ALL — all methods at once. This makes the module suitable not only for regular sites, but also for CMS with API, personal accounts, game panels and administrative actions. Limit storage: Redis, APCu and file fallback In the new version, the module supports several options for storing temporary data. Available modes: Redis; APCu; file fallback. The auto mode tries to use the most suitable option: Redis; APCu; file storage as a fallback. Redis or APCu are suitable for more efficient operation, while the file storage is left as a fallback option for simple hosting environments that do not have additional extensions. JSONL logging The module records protection events in JSON Lines format. Logs are saved in the following file: storage/logs/ddos_guard.jsonl This format is more convenient than a regular text log, because each event is stored as a separate JSON record. The logs can record the following information: event time; IP address; HTTP method; URL; name of the triggered rule; reason for blocking; number of requests; action status; user-agent; protection mode. The JSONL format is convenient for analysis by external tools, log agents, and monitoring systems. Prometheus metrics DDoS Guard Pro v2.0 adds an endpoint for receiving metrics in Prometheus format. Endpoint: /?ddos_guard_metrics=TOKEN The token is set in the module settings. Metrics allow you to track: the number of processed requests; the number of rule activations; the number of blocks; activity by limits; protection events; module status. This allows you to connect monitoring and configure alerts so that the administrator can see when suspicious activity starts on the site. LOG ONLY mode The module has a LOG ONLY mode. In this mode, DDoS Guard Pro does not block users, but only records events and potential triggers in the log. This mode is recommended to be used after installation, in order to first see which rules are triggered, and only then to enable the real blocking.  This helps to avoid too strict limits and random blocking of regular users.  Support for Cloudflare and proxy  The module supports working behind Cloudflare or another reverse proxy.  With proper configuration, it is possible to take into account the real IP of the user, and not the IP of the proxy server.  This is important for sites that use:  Cloudflare; nginx reverse proxy; load balancers; CDN; hosting proxy protection. Nginx-recommendations DDoS Guard Pro v2.0 contains an example nginx-config: modules/ddos_guard/nginx-ddos-guard-example.conf This allows you to use the module as an additional application layer of protection, and to move the main coarse limits to the nginx level. Recommended protection scheme: Cloudflare / nginx / firewall → DDoS Guard Pro → PlayMMO CMS This approach is more correct than trying to solve all problems only at the PHP level.
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..